ALTER TABLE CONTARECEBER DROP CONSTRAINT CKC_IDREPFOSCNC
/

ALTER TABLE CONTARECEBER ADD CONSTRAINT CKC_IDREPFOSCNC CHECK (IDREPFOSCNC IN ('R', 'N', 'M', 'D',NULL))
/

DECLARE
V_COUNT NUMBER;
BEGIN
V_COUNT := 0;
   FOR C_CONTAS IN (SELECT CR.ROWID, DECODE(NF.IDSISTEMA, 'TMP','N','CNC','R','REC','M','D') AS ID, IDREPFOSCNC
                      FROM CONTARECEBER CR, NOTAFISCAL NF
                     WHERE CR.CDFILIAL = NF.CDFILIAL
                       AND CR.NRLANCTONF = NF.NRLANCTONF
                       AND NF.DTENTRSAID >= '01/01/2021') LOOP
                  V_COUNT := V_COUNT + 1;     
      UPDATE CONTARECEBER
         SET IDREPFOSCNC = C_CONTAS.ID
        WHERE ROWID = C_CONTAS.ROWID;
      IF V_COUNT = 5000 THEN
         V_COUNT := 0;
         COMMIT;
      END IF;
   END LOOP;
   COMMIT;
END;
/