CREATE OR REPLACE PROCEDURE PROVISAO_RECEITA(
P_CDRECEITA IN VARCHAR2,
P_QTRECEITA IN FLOAT,
P_NRPRODUCAOCOC IN OUT FLOAT
)
AS
V_NRPRODUCAOCOC VARCHAR2(20);
BEGIN
   IF P_CDRECEITA IS NULL OR P_QTRECEITA IS NULL OR P_QTRECEITA <= 0 THEN
      RETURN;
   END IF;
   IF P_NRPRODUCAOCOC IS NULL THEN
      NOVO_CODIGO_SC('PRODUCAOCOC',V_NRPRODUCAOCOC);
      P_NRPRODUCAOCOC := TO_NUMBER(V_NRPRODUCAOCOC);
   ELSE
      DELETE FROM PRODPRODUCOC WHERE NRPRODUCAOCOC = P_NRPRODUCAOCOC;
      DELETE FROM SUBRECPRODUCOC WHERE NRPRODUCAOCOC = P_NRPRODUCAOCOC;
      DELETE FROM RECPRODUCOC WHERE NRPRODUCAOCOC = P_NRPRODUCAOCOC;      
   END IF;
   
   COMPOSICAO_RECEITA_PROVRECCOC(P_CDRECEITA, P_QTRECEITA, 0, P_NRPRODUCAOCOC);
END;
/
-- VERSAO --
BEGIN ATUVEROBJ('PROVISAO_RECEITA','5.85.xxx'); END;
/