CREATE OR REPLACE FUNCTION CUSTO_DIA_CARDTRAB
(
   P_NRCARDAPIOTRAB IN NUMBER,
   P_NRDIACARDTRAB IN NUMBER
) RETURN FLOAT
AS
   V_VRCUSTO FLOAT := 0;
BEGIN
   SELECT SUM(NVL(C.VRPECONSCARDTRAB/100 * D.QTCOMENSAIS, 0) * CUSTO_PRAT_CARDTRAB(C.NRCARDAPIOTRAB, C.CDFILAUXPRAT, C.CDPRATO))
     INTO V_VRCUSTO
        FROM COMPCARDTRAB C             
             INNER JOIN DIACARDTRAB D ON D.NRDIACARDTRAB = C.NRDIACARDTRAB
       WHERE C.NRCARDAPIOTRAB = P_NRCARDAPIOTRAB
         AND C.NRDIACARDTRAB = P_NRDIACARDTRAB;
   
   RETURN ROUND(NVL(V_VRCUSTO, 0), 5);
END;
/