CREATE OR REPLACE FUNCTION CLASSFISCAL
   (P_CDFILIAL    IN IMPOSNFTOT.CDFILIAL%TYPE,
    P_NRLANCTONF  IN IMPOSNFTOT.NRLANCTONF%TYPE) RETURN STRING
AS
   V_RESULT VARCHAR2(1);
BEGIN

   V_RESULT := '1';
   FOR C_IMPOSTO IN (SELECT CDIMPOSTO
                     FROM IMPOSNFTOT
                     WHERE CDFILIAL   = P_CDFILIAL  AND
                           NRLANCTONF = P_NRLANCTONF) LOOP

      IF C_IMPOSTO.CDIMPOSTO = '00' THEN
         V_RESULT := '1';
      ELSIF (C_IMPOSTO.CDIMPOSTO = '30') OR (C_IMPOSTO.CDIMPOSTO = '31') THEN
         IF V_RESULT = '1' THEN
            V_RESULT := '3';
         ELSE
            V_RESULT := '2';
         END IF;
      END IF;
   END LOOP;

   RETURN (V_RESULT);

END;
/

