Bulk Collect / Forall insert PLS-00436 error.

Scarlett72
Scarlett72 used Ask the Experts™
on
Hi, I am running the following code to create a forall insert but I am receiving the following error and cannot figure out why ...  I'm not sure what this error message is telling me.  Thanks,

ORA-06550: line 34, column 4:
PLS-00436: implementation restriction: cannot reference fields of BULK In-BIND table of records

Open in new window


create table tmp_table1 as select col1, col2, col3, col4, col5, col6 from table1 where 1 = 2;

declare

cursor curOrders is
select 
 a.col1, a.col2, a.col3, a.col4, a.col5, a.col6
 from
 table1 a
 join
table2 b
on a.col1 = b.col1 and a.col2 = b.col2;

type tbl_bulk is table of curOrders%rowtype;

varOrders tbl_bulk;

begin
open curOrders;
loop
fetch  curOrders bulk collect into varOrders limit 500;
  
forall indx in 1 .. varOrders.count
  
  insert into  tmp_table1
  (col1, col2, col3, col4, col5, col6)
  values
  (varOrders(indx).col1, varOrders(indx).col2, varOrders (indx).col3, varOrders(indx).col4, varOrders(indx).col5, varOrders(indx).col6);

exit when curOrders%notfound;
 --exit when varClaims.count < 500;  which is better?
   end loop;

close curOrders;
commit;
end;
/

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
What is your Oracle version (all 4 numbers please)?

I just set up a test case and your exact code runs fine with 11.2.0.2.

You could make the forall a simple for loop.

for indx in 1 .. varOrders.count loop
 
  insert into  tmp_table1
  (col1, col2, col3, col4, col5, col6)
  values
  (varOrders(indx).col1, varOrders(indx).col2, varOrders (indx).col3, varOrders(indx).col4, varOrders(indx).col5, varOrders(indx).col6);

end loop;

Author

Commented:
Hi slightwv, the version I'm using is 10.2.0.5.0
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
Can't test with that.

Try the regular for loop instead of forall.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Have you tried:
forall indx in 1 .. varOrders.count
    insert into  tmp_table1 values varOrders(indx);

Open in new window

Author

Commented:
Hi Alexander and slightwv, both worked.  Thank you, I am trying to harness the forall clause so Alexander your solution fit best, before I assign and close off this thread, would either of you know why I received the error?  using Alexanders solution I can't reference the individual columns in the cursor record?
Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
>>using Alexanders solution I can't reference the individual columns in the cursor record?

Not in the forall statement.  Not sure why using the row object worked and individual columns did not but it is 10g.  Could be a bug.

The reason for this post is you will likely need to be careful.

The row object will work as long as the cursor and table have the same columns.  My guess is that if you add a column to table1, which will end up in tmp_table1, and try it with the cursor you have, that doesn't have the new column, it will generate an error.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial