10-12. Increasing the Size of a Collection

Problem

You have a VARRAY with a defined maximum size, but not all elements are initialized, and you need to add more elements to the collection.

Solution

Use the EXTEND method to create new elements within the predefined boundaries. The following example adds five elements using a loop:

DECLARE TYPE    vtype   IS VARRAY(5) OF DATE; vdates  vtype := vtype (sysdate, sysdate+1, sysdate+2); -- initialize 3 of the 5 elements BEGIN    DBMS_OUTPUT.PUT_LINE ('vdates size is: ' || vdates.COUNT);    FOR i IN 1..5 LOOP       if NOT vdates.EXISTS(i) then          vdates.EXTEND;          vdates(i) := SYSDATE + i;       END IF;    END LOOP;    DBMS_OUTPUT.PUT_LINE ('vdates size is: ' || vdates.COUNT); END; ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.