Middle
BEGIN LOOP UPDATE table SET status = 'PROCESSED' WHERE category = 'OLD' AND ROWNUM <= 50000; EXIT WHEN SQL%NOTFOUND; COMMIT; END LOOP;
sobes.tech AI
Answer from AI
This code is an example of a PL/SQL loop for batch updating rows in a table with a limit on the number of records updated per iteration.
Explanation:
- The loop updates up to 50,000 rows with the category 'OLD', setting the status to 'PROCESSED'.
- After each iteration, a COMMIT is performed to save the changes.
- The loop ends when there are no more rows to update (SQL%NOTFOUND).
This approach helps avoid locks and undo/redo log overflow when updating large volumes of data.
An improvement example is to use BULK COLLECT and LIMIT for more efficient processing, or to break updates into smaller batches.