DECLARE V_COUNT NUMBER := 0;
BEGIN
  FOR C_LOG IN (SELECT NRAUTOFORN, CDFILDEST, CDFILLANC, NRORG 
                  FROM LOGDOWNLOADAF 
                 GROUP BY NRAUTOFORN, CDFILDEST, CDFILLANC, NRORG) LOOP
    UPDATE AUTOFORNE SET IDSTATLEITURA = 'S'
     WHERE NRAUTOFORN = C_LOG.NRAUTOFORN
       AND CDFILDEST  = C_LOG.CDFILDEST
       AND CDFILLANC  = C_LOG.CDFILLANC
       AND NRORG      = C_LOG.NRORG;
    IF V_COUNT > 1000 THEN
      V_COUNT := 0;
      COMMIT;
    ELSE
      V_COUNT := V_COUNT + 1;
    END IF;    
  END LOOP;
  COMMIT;
END;
/