Bulk Collect / Forall insert PLS-00436 error.

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

Scarlett72Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) 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;
Scarlett72Author Commented:
Hi slightwv, the version I'm using is 10.2.0.5.0
slightwv (䄆 Netminder) Commented:
Can't test with that.

Try the regular for loop instead of forall.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Alex [***Alex140181***]Software DeveloperCommented:
Have you tried:
forall indx in 1 .. varOrders.count
    insert into  tmp_table1 values varOrders(indx);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scarlett72Author 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?
slightwv (䄆 Netminder) 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.