cc.
cc.

Reputation: 5633

PLSQL Collections - how to use table of records?

I'm new to PL/SQL and I'm trying to use a table of records, but I don't know how to use this feature. What is the problem?

    DECLARE
    TYPE TIP
    IS
        RECORD
        (
            F1 SMALLINT,
            F2 SMALLINT);
    TYPE Ve
    IS
        TABLE OF TIP;
v ve;
        IND SMALLINT := 0;
    BEGIN
        WHILE(IND<20)
        LOOP
            IND       := IND + 1;
            V(IND).F2 := IND-1;
            V(IND).F2 := IND;
        END LOOP;
    END; 

What I'm doing wrong?

06531. 00000 -  "Reference to uninitialized collection"

Upvotes: 2

Views: 2112

Answers (1)

Thomas Jones-Low
Thomas Jones-Low

Reputation: 7161

You need to make two changes.

v ve := ve(); 

This initializes the V array. This will create an empty VE table.

IND       := IND + 1;
v.extend(IND+1);
V(IND).F2 := IND-1;
V(IND).F2 := IND;

Next is the call to v.EXTEND() to make sure the table has enough entries to hold your values. This now functions correctly.

Upvotes: 4

Related Questions