I am working on an application that performs bulk insertion(~12k but it can be more than that) in the Oracle database.
Below is the SQL script:-
DECLARE
errstr VARCHAR2(4000) := '';
errors NUMBER;
i NUMBER;
er NUMBER;
bk1 acct_common.type_tabnumber;
bk2 acct_common.type_tabdate;
bk3 acct_common.type_tabnumber;
bk49 acct_common.type_tabnumber;
BEGIN
bk1 := :1;
bk2 := :2;
bk3 := :3;
bk49 := :49;
FORALL i IN 1..11655
INSERT INTO table_name (
col1,
col2,
col3,
col49
) VALUES (
bk1(i),
bk2(i),
bk3(i),
bk49(i)
);
END;
And the insertion fails with the below error:-
oci error 6531 (ORA-06531: Reference to uninitialized collection ORA-06512: at line 126 ORA-22160: element at index [1] does not exist ORA-06512: at line 106 )
As there are thousands of records, I am not able to figure out which record is having the data issue.
(This query is being generated dynamically with PHP and is being executed with Oracle OCI8)
Can someone please help me with how can i debug/print the specific record data which is failing the script?
Would really appreciate your help. Thanks!
2
Answers
Collections are to be initialized like in the example below:
The previous example would initialize the collection with a number of elements.
Or it could be something like:
You may not pass a collection as a simple bind-variable, like you wish. That’s from the Oracle side. As to the client application that sends data to Oracle I don’t know how you would bulk bind there a collection.
As the exception states, you have not initialised the collection.
Assuming that
:1
,:2
,:3
and:49
are bind variables and you are binding a PL/SQL associative array defined in a package. Based on theoci_bind_array_by_name
documentation you can use something like (untested as I do not have a PHP environment):