Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ORA-06531: Reference to uninitialized collection

Lokesh AMay 11 2022

set SERVEROUTPUT ON
Declare
type t is table of Varchar2(6);
v_t1 t:= t();--initialized collection variable

Begin
v_t1.extend(6);
v_t1(1):='Lokesh';
v_t1(2):='Ashok';
v_t1(3):='Mahesh';
v_t1(4):='Ramu';
v_t1(5):='Ajay';
v_t1(6):='Irani chawla';

for i in v_t1.first..v_t1.last loop
dbms_output.put_line('Hi v_t1='||v_t1(i));
end loop;

forall i in v_t1.first..v_t1.last save exceptions
insert into temp99 values(v_t1(i));

Exception when others then
dbms_output.put_line('bulk exception count='||sql%bulk_exceptions.count);
for i in 1..sql%bulk_exceptions.count loop
dbms_output.put_line('bulk exception index='||sql%bulk_exceptions(i).error_index);
dbms_output.put_line('bulk exception code='||sql%bulk_exceptions(i).error_code);
end loop;
End;

My table structure is
create table temp99(tname Varchar2(6))

Getting error like

Error report -
ORA-06531: Reference to uninitialized collection
ORA-06512: at line 22
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 12
06531. 00000 - "Reference to uninitialized collection"
*Cause: An element or member function of a nested table or varray
was referenced (where an initialized collection is needed)
without the collection having been initialized.
*Action: Initialize the collection with an appropriate constructor
or whole-object assignment.

I want to use error index and error code, so my table structure is varchar2(6) only.
If i am removing v_t1(6):='Irani chawla'; collection vallue then executing fine but when i am using
v_t1(6):='Irani chawla'; collection value facing same issue. please suggest i went through google also but not getting any idea

This post has been answered by Frank Kulash on May 11 2022
Jump to Answer
Comments
Post Details
Added on May 11 2022
4 comments
4,368 views