Manoj Stack
Manoj Stack

Reputation: 9

Reference to uninitialized collection error

create or replace function cmp return number as

    type GyomuAuth1D is table of char(2);
    type GyomuAut2D_type is table of GyomuAuth1D;
    GyomuAut2D GyomuAut2D_type;   

begin
    for x in 1..50
    loop
        GyomuAut2D(x)(0) := null; 
    end loop;
end;

I am trying to assign null to first 50 places of the 2D array with for loop. But it is showing "Reference to uninitialized collection" error Can anyone spot what mistake i have done... Thanks in advance

Upvotes: 1

Views: 365

Answers (1)

William Robertson
William Robertson

Reputation: 16001

First you need to initialise GyomuAut2D. It is still empty though, so there is no element 1 until you extend it (otherwise you'll get ORA-06533: Subscript beyond count). I've chosen to extend(50) once for efficiency since we know how many we want, although you could also extend once per loop iteration.

The same applies to each GyomuAut2D(x) as it is also an uninitialised and empty collection.

Also the function needs to return something.

declare
    function cmp
        return number
    is
        type GyomuAuth1D is table of varchar2(2);
        type GyomuAut2D_type is table of GyomuAuth1D;
        GyomuAut2D GyomuAut2D_type := GyomuAut2D_type();
    begin
        GyomuAut2D.extend(50);

        for x in 1..50
        loop
            GyomuAut2D(x) := GyomuAuth1D(null);
        end loop;

        return GyomuAut2D.count;
    end;
begin
    dbms_output.put_line(cmp);
end;

Upvotes: 2

Related Questions