10-14. Trimming a Collection

Problem

You need to remove one or more items from the end of a non-INDEX BY collection. The DELETE method will not work because it applies only to INDEX BY collections.

Solution

Use the TRIM method to remove one or more elements from the end of the collection. In this example, a VARRY is initialized with five elements. The TRIM method is used to remove elements from the end of the collection.

DECLARE TYPE    vtype   IS VARRAY(5) OF DATE; vdates  vtype := vtype (sysdate, sysdate+1, sysdate+2, sysdate+3, sysdate+4); BEGIN    DBMS_OUTPUT.PUT_LINE ('vdates size is: ' || vdates.COUNT);    vdates.TRIM;    DBMS_OUTPUT.PUT_LINE ('vdates size is: ' || vdates.COUNT);    vdates.TRIM(2);    DBMS_OUTPUT.PUT_LINE ('vdates size ...

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.