COUNT v14

COUNT is a method that returns the number of elements in a collection. The syntax for using COUNT is:

<collection>.COUNT

Where collection is the name of a collection.

For a varray, COUNT always equals LAST.

This example shows that an associative array can be sparsely populated, with gaps in the sequence of assigned elements. COUNT includes only the elements that were assigned a value.

DECLARE
    TYPE sparse_arr_typ IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
    sparse_arr      sparse_arr_typ;
BEGIN
    sparse_arr(-100)  := -100;
    sparse_arr(-10)   := -10;
    sparse_arr(0)     := 0;
    sparse_arr(10)    := 10;
    sparse_arr(100)   := 100;
    DBMS_OUTPUT.PUT_LINE('COUNT: ' || sparse_arr.COUNT);
END;

The following output shows that there are five populated elements included in COUNT:

COUNT: 5