CREATE OR REPLACE FUNCTION VALOR_REDUCAO_NF
   (P_CDFILIAL    IN ITEMPRODUTO.CDFILIAL%TYPE,
    P_NRLANCTONF  IN ITEMPRODUTO.NRLANCTONF%TYPE,
    P_CDIMPOSTO   IN IMPOSTO.CDIMPOSTO%TYPE) RETURN NUMBER
AS
   V_VRCONTITIMP  ITEMPROIMPOS.VRBASECALCIT%TYPE;
BEGIN
   SELECT SUM(VRCONTITIMP)
     INTO V_VRCONTITIMP
     FROM ITEMPROIMPOS
    WHERE CDFILIAL = P_CDFILIAL
      AND NRLANCTONF = P_NRLANCTONF
      AND NRITPROIMPOS = '2'
      AND CDIMPOSTO = P_CDIMPOSTO;
    RETURN(V_VRCONTITIMP);
END;
/