DECLARE V_IDENTRSAIDOP  VARCHAR2(01);
        V_CDTIPOOPER    VARCHAR2(02);
        V_COUNT         NUMBER;
BEGIN
  FOR C_FILIAL IN (SELECT CDFILIAL
                     FROM FILIAL)
  LOOP
      V_IDENTRSAIDOP := NULL;
      V_CDTIPOOPER   := NULL;
      V_COUNT        := 0;

      FOR C_DADOS IN (SELECT CDFILIAL, NRLANCTONF, NRLANCESTQ
                        FROM LANCTOESTOQ L
                       WHERE L.CDFILIMOVI = C_FILIAL.CDFILIAL
                         AND L.DTLANCESTQ BETWEEN '01/06/2023' AND SYSDATE
                         AND L.NRLANCTONF IS NOT NULL
                         AND L.CDTIPOOPER IS NULL)
      LOOP
         BEGIN
         SELECT N.IDENTRSAIDOP, N.CDTIPOOPER
           INTO V_IDENTRSAIDOP, V_CDTIPOOPER
           FROM NOTAFISCAL N
          WHERE CDFILIAL = C_DADOS.CDFILIAL
            AND NRLANCTONF = C_DADOS.NRLANCTONF;
         EXCEPTION
             WHEN OTHERS THEN
                V_IDENTRSAIDOP := NULL;
                V_CDTIPOOPER   := NULL;
         END;

         UPDATE LANCTOESTOQ
            SET IDENTRSAIDOP = V_IDENTRSAIDOP,
                CDTIPOOPER = V_CDTIPOOPER
          WHERE CDFILIAL = C_DADOS.CDFILIAL
            AND NRLANCESTQ = C_DADOS.NRLANCESTQ;

         UPDATE ITLANCTOEST
            SET IDENTRSAIDOP = V_IDENTRSAIDOP,
                CDTIPOOPER = V_CDTIPOOPER
          WHERE CDFILIAL = C_DADOS.CDFILIAL
            AND NRLANCESTQ = C_DADOS.NRLANCESTQ;

          V_COUNT := V_COUNT + 1;

          IF V_COUNT > 250 THEN
             V_COUNT := 0;
             COMMIT;
          END IF;
      END LOOP;
  END LOOP;
  COMMIT;
END;
/