CREATE OR REPLACE FUNCTION CUSTO_PRAT_CARDTRAB
(
   P_NRCARDAPIOTRAB IN NUMBER,
   P_CDFILAUXPRAT IN VARCHAR2,
   P_CDPRATO IN VARCHAR2
) RETURN FLOAT
AS
   V_VRCUSTO FLOAT := 0;
BEGIN
   SELECT SUM(NVL(QTBRUTACARDTRABUNR, 0) * CUSTO_PROD_CARDTRAB(NRCARDAPIOTRAB, CDPRODUTO))
     INTO V_VRCUSTO
     FROM
   (
    SELECT QTBRUTACARDTRABUNR, NRCARDAPIOTRAB, CDPRODUTO     
      FROM RECEPRATCARDTRAB
     WHERE NRCARDAPIOTRAB = P_NRCARDAPIOTRAB
       AND CDFILAUXPRAT = P_CDFILAUXPRAT
       AND CDPRATO = P_CDPRATO
   ) S;
   RETURN ROUND(NVL(V_VRCUSTO, 0), 5);
END;
/