10-9. Counting the Members in a Collection
Problem
You have a collection, and you need to determine the total number of elements in the collection.
Solution
Invoke the built-in COUNT
method on the collection. For example, the following code creates two collections: a varying array and an INDEX BY
array. The code then invokes the COUNT
method on both collections, doing so before and after adding some records to each.
DECLARE
TYPE vtype IS VARRAY(3) OF DATE;
TYPE ctype IS TABLE OF DATE INDEX BY BINARY_INTEGER;
vdates vtype := vtype (sysdate);
cdates ctype;
BEGIN
DBMS_OUTPUT.PUT_LINE ('vdates size is: ' || vdates.COUNT);
DBMS_OUTPUT.PUT_LINE ('cdates size is: ' || cdates.COUNT);
FOR i IN 1..3 LOOP cdates(i) := SYSDATE ...
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.