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 in Varray

3229692Dec 12 2016 — edited Dec 12 2016

Hi Experts,

Need help in above error. i am using Varray for processing multi-column data in PLSQL data.

Below is the code. This code is executing but also giving above error in the output screen.

Also find the error which we are getting. Here I am also getting the expected output but also with the error. Can anybody guide me solving this issue?

===============================CODE=====================================

declare

  

    today_date  DATE := TRUNC(SYSDATE);

    v_count  NUMBER := 0;

    Type QNUMBER_ARRAY is varray(4) of varchar2(255);

    Type QNUMBER_TYPE IS TABLE OF QNUMBER_ARRAY;

    QNUMBER QNUMBER_TYPE := QNUMBER_TYPE();

 

begin   

  

   QNUMBER := new QNUMBER_TYPE(null);

    --QNUMBER := QNUMBER_TYPE();

   QNUMBER.EXTEND(100);

    --

   QNUMBER (1) := QNUMBER_ARRAY('QXH8000','15-NOV-16','31-DEC-9999','Admin');

   QNUMBER (2) := QNUMBER_ARRAY('QXN1326','15-NOV-16','31-DEC-9999','AG');

   QNUMBER (3) := QNUMBER_ARRAY('QXI1870','15-NOV-16','31-DEC-9999','VG_DE');

   QNUMBER (4) := QNUMBER_ARRAY('QXK9666','15-NOV-16','31-DEC-9999','VG_CH');

    DBMS_OUTPUT.put_line( '1 ' || QNUMBER(1)(1) );

   

    FOR i IN 1 .. QNUMBER.count

    LOOP

   

    DBMS_OUTPUT.put_line( '5 ' || QNUMBER(i)(1) );

    DBMS_OUTPUT.put_line( '6 ' || QNUMBER(i)(2) );

    DBMS_OUTPUT.put_line( '7 ' || QNUMBER(i)(3) );

    DBMS_OUTPUT.put_line( '8 ' || QNUMBER(i)(4) );    

   

    END LOOP;

   

end;

==========================================================================

Below is the error which we are getting.

=============================ERROR=======================================

ORA-06531: Reference to uninitialized collection

ORA-06512: at line 26

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.

1 QXH8000

5 QXH8000

6 15-NOV-16

7 31-DEC-9999

8 Admin

5 QXN1326

6 15-NOV-16

7 31-DEC-9999

8 AG

5 QXI1870

6 15-NOV-16

7 31-DEC-9999

8 VG_DE

5 QXK9666

6 15-NOV-16

7 31-DEC-9999

8 VG_CH

====================================================================

This post has been answered by Alexander Jeremy Kogoj on Dec 12 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2017
Added on Dec 12 2016
5 comments
1,756 views