CREATE OR REPLACE
FUNCTION MAIOR_ALIQUOTA (P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
                         P_NRLANCTONF   IN NOTAFISCAL.NRLANCTONF%TYPE,
                         P_CDIMPOSTONFE IN IMPOSTO.CDIMPOSTONFE%TYPE) RETURN NUMBER IS

   V_VRALIQITEM      NUMBER;
   V_NRSEQITPROD     VARCHAR2(04);
BEGIN
   V_VRALIQITEM := -1;
   V_NRSEQITPROD := '0000';
   FOR C_ITEM IN (SELECT II.NRSEQITPROD, II.VRALIQITEM
                    FROM ITEMPROIMPOS II , IMPOSTO I
                   WHERE II.CDFILIAL = P_CDFILIAL
                     AND II.NRLANCTONF = P_NRLANCTONF
                     AND II.CDIMPOSTO = I.CDIMPOSTO
                     AND I.CDIMPOSTONFE IN ('31', '35', '36')) LOOP
      IF C_ITEM.VRALIQITEM > V_VRALIQITEM THEN
         V_VRALIQITEM := C_ITEM.VRALIQITEM;
         V_NRSEQITPROD := C_ITEM.NRSEQITPROD;
      END IF;
   END LOOP;
   RETURN(V_NRSEQITPROD);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('MAIOR_ALIQUOTA','5.60.xxx'); END;
/
