using sequence in Dynamic sql
I have a dynamic sql :
forall k in 1..Job_ID.COUNT Save exceptions
EXECUTE IMMEDIATE 'insert into XYZ values(:1,:2,:3)' using sequence_one.NextVal,job_id(k),Name(k);
///Exception hand开发者_Go百科ling.
On running the abouve query only one row is getting inserted.And following error is thrown:
ORA-24381: error(s) in array DML.
Any idea why above thing is happening?
Do you really want every inserted row to have the same sequence value in the first column? If not you should do this:
forall k in 1..Job_ID.COUNT Save exceptions
EXECUTE IMMEDIATE 'insert into XYZ values(sequence_one.NextVal,:2,:3)'
using job_id(k),Name(k);
Or even better (unless you have a good reason for using dynamic SQL:
forall k in 1..Job_ID.COUNT Save exceptions
insert into XYZ values(sequence_one.NextVal, job_id(k), Name(k));
精彩评论