CARDINALITY Function
The CARDINALITY function returns the number of elements in a collection column (SET, MULTISET, LIST).
The CARDINALITY function has the following syntax.
Element | Description | Restrictions | Syntax |
---|---|---|---|
collection_col | An existing collection column | Must be declared as a collection data type | Identifier |
collection_var | Host or program collection variable | Must be declared as a collection data type | Language specific |
Suppose that the set_col SET column contains the
following value:
{3, 7, 9, 16, 0}
The following SELECT statement returns 5 as the number
of elements in the set_col column:
SELECT CARDINALITY(set_col) FROM table1;
If the collection contains duplicate elements, CARDINALITY counts each individual element.