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!

is a FORALL insert paired with RETURNING id BULK COLLECT INTO myTable sequential?

Alex SimJun 5 2025 — edited Jun 5 2025

As far as I understand, FORALL is not sequential per-se: if I execute a series of INSERT statements inside a FORALL, they may be optimized to run asyncronously/unsequentially (and also allows me to use the APPEND_VALUES and PARALLEL hint);

But will the result of the bulk collect also reflect the asyncronous execution?

Let's say I pass a SYS.ODCIVARCHAR2LIST as input, as well as v_count representing the collection size, then do:

FORALL idx IN 1..v_count
	INSERT INTO my_table (id, value) values (seq_my_table_ids.nextval, my_varray(idx))
	RETURNING id BULK COLLECT INTO returned_ids;

OPEN my_out_cursor FOR SELECT column_value FROM TABLE(returned_ids);

Can i assume the index of returned_ids obtained this way will match the index of the array passed as input (or in other words returned_ids(i) is the ID of the record that used my_varray(i) as value)?

From my tests, this seems to be the case, but I wanted to make sure this is a safe assumption to make

Comments
Post Details
Added on Jun 5 2025
1 comment
156 views