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

Oracle DatabaseDatabases

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Scarlett72
Scarlett72

ASKER

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.
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo