views:

124

answers:

1

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"
+2  A: 

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.

Thomas Jones-Low