I run into an interesting and unexpected issue when processing records in Oracle (11g) using BULK COLLECT.
The following code was running great, processing through
The problem is that you're trying to do a fetch across a commit.
When you open My_Data_Cur
with the for update
clause, Oracle has to lock every row in the My_Data_1
table before it can return any rows. When you commit
, Oracle has to release all those locks (the locks Oracle creates do not span transactions). Since the cursor no longer has the locks that you requested, Oracle has to close the cursor since it can no longer satisfy the for update
clause. The second fetch, therefore, must return 0 rows.
The most logical approach would almost always be to remove the commit
and do the entire thing in a single transaction. If you really, really, really need separate transactions, you would need to open and close the cursor for every iteration of the loop. Most likely, you'd want to do something to restrict the cursor to only return 100 rows every time it is opened (i.e. a rownum <= 100
clause) so that you wouldn't incur the expense of visiting every row to place the lock and then every row other than the 100 that you processed and deleted to release the lock every time through the loop.