CREATE OR REPLACE FUNCTION RETURN_CLASSE_PADR
   (P_CDCIA   IN COMPANHIA.CDCIA%TYPE,
    P_CDSERVICO IN SERVICOCIA.CDSERVICO%TYPE) RETURN STRING
AS
   V_RESULT VARCHAR2(5);
BEGIN
   IF (P_CDSERVICO IN ('9020300200', '9010300200')) THEN
      V_RESULT := ' ';
   ELSE
      SELECT NVL(RPAD(SUBSTR(MAX(PS.SGPADSERV),5,1),1), ' ')
      INTO V_RESULT
      FROM SERVICOCIA SC, PADSERVICO PS
      WHERE SC.CDCIA     = P_CDCIA     AND
            SC.CDSERVICO = P_CDSERVICO AND
            PS.CDPADSERV = SC.CDPADSERV;
   END IF;

   RETURN(V_RESULT);
END;

/

