I ran into an interesting and unexpected problem when processing records in Oracle (11g) using BULK COLLECT.
The following code worked perfectly, processing all millionth records without problems:
cursor My_Data_Cur Is
Select col1
,col2
from My_Table_1;
…
open My_Data_Cur;
loop
fetch My_Data_Cur
bulk collect into My_Data_Rec
limit 100;
Exit when My_Data_Rec.count = 0;
for idx in 1 .. My_Data_Rec.count
loop
… do work here to populate a records to be inserted into My_Table_2 …
end loop;
forall idx in 1 .. My_Data_Rec.count
insert into My_Table_2…;
forall idx in 1 .. My_Data_Rec.count
delete from My_Table_1 …;
commit;
end loop;
Since at the end of processing each group of 100 records (the limit is 100), we delete the records that we just read and processed, although it would be nice to add the syntax “for updating” to the cursor definition so that another process could not update any of the records between the time the data was read and the time the record was deleted.
So the only thing that I changed in the code was ...
cursor My_Data_Cur
is
select col1
,col2
from My_Table_1
for update;
PL/SQL , 100 , . , , " " , .
, " " ? , ? , , , .
,