Link to home
Start Free TrialLog in
Avatar of Scarlett72
Scarlett72

asked on

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

SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scarlett72
Scarlett72

ASKER

Hi slightwv, the version I'm using is 10.2.0.5.0
Can't test with that.

Try the regular for loop instead of forall.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
>>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.