web analytics

ORA-06531: reference to uninitialized collection

Options

codeling 1602 - 6666
@2017-02-03 13:09:19

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

@2017-02-03 13:31:53

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;

@2017-02-03 13:35:16

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;

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com