web analytics
ORA-06531: reference to uninitialized collection Options
codeling
Posted: Friday, February 3, 2017 1:09:19 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 984
Points: 4146

When I try to run the following Oracle PL/SQL block:

I got the error:

ORA-06531: Reference to uninitialized collection
ORA-06512: at line 11

Sponsor
Posted: Friday, February 3, 2017 1:09:19 PM
codeling
Posted: Friday, February 3, 2017 1:31:53 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 984
Points: 4146

The nested table variable has to be initialized and extended before you can use it in the assignement statement.

declare

type nested_type is table of number;

v1 nested_type := nested_type();

begin

   for i in 1..10

   loop

      v1.extend;

      v1(i) := i;

   end loop;

   for j in 1..v1.COUNT

   loop

      dbms_output.put_line(v1(j));

   end loop;

end;

codeling
Posted: Friday, February 3, 2017 1:35:16 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 984
Points: 4146

You can also define v1 as a variable of an associative array type, then it will be initialized automatically.

declare

type nested_type is table of number INDEX BY PLS_INTEGER;

v1 nested_type;

begin

   for i in 1..10

   loop

      v1(i) := i;

   end loop;

   for j in 1..v1.COUNT

   loop

      dbms_output.put_line(v1(j));

   end loop;

end;

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2018 Digcode.com. All rights reserved.