Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

LOOP inside FORALL in bulk binding

JambalahotNov 21 2009 — edited Nov 21 2009
Can I use a loop inside forall in bulk bind updates?

as I understand, forall statement strictly loops through the length of the bulk limit size for the immediately following statement only.

I am attempting to use a loop there to update more than one table.

cursor c is select id from temp where dt_date > sysdate-30;

BEGIN
loop
fetch c into v_id;
limit 1000;
forall i in 1..v_id.count
UPDATE table_one set new_id = v_id(i);

exit when C%NOTFOUND;
end loop;
end;


I want to update another table table_two also immediately after updating table_one like this:

forall i in 1..v_id.count

UPDATE table_one set new_id = v_id(i);
BEGIN select nvl(code,'N/A') into v_code from T_CODES where ID_NO = v_id(i); EXCEPTION WHEN NO_DATA_FOUND v_code='N/A'; END;
UPDATE table_two set new_code =v_code;
exit when C% not found.


This is not working and when I run it, I get an error saying encountered BEGIN when one of the following is expected.

I got around this by having another FOR loop just to set up the values in another array variable and using that value in another second forall loop to update table_two.

Is there any way to do this multiple table udpates in bulkbinding under one forall loop that would enable to do some derivation/calculation if needed among variables [not array variables, regular datatype variables].

Can we have like

forall j in 1.. v_id.count

LOOP

update table 1;
derive values for updating table 2;
update table 2;
END LOOP;


Thank You.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2009
Added on Nov 21 2009
5 comments
1,152 views