ORA-06531: Reference to uninitialized collection PLSQL

ORA-06531: Reference to uninitialized collection

Error Description:
Reference to uninitialized collection Error 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.

CREATE OR REPLACE TYPE l_rec_type IS OBJECT (id NUMBER, name VARCHAR2 (1111));

/

CREATE OR REPLACE TYPE l_tab_type IS TABLE OF l_rec_type;

/

DECLARE
  l_tab l_tab_type;
 BEGIN
  l_tab.EXTEND(2);
  l_tab(1) := l_rec_type(1,'Ashish');
  l_tab(2) := l_rec_type(2,'Sahay');
 END;
/

After Initializing the collection.

DECLARE
  l_tab l_tab_type;
 BEGIN

  l_tab := l_tab_type();

  l_tab.EXTEND(2);

  l_tab(1) := l_rec_type(1,'This is test1');

  l_tab(2) := l_rec_type(2,'This is test2');

 END;
/


Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *