Friday 6 December 2013

Cardinality functions in plsql

In PL/SQL, it has always been trivial to get a count of elements in an array or collection, using the COUNT pseudo-method. The new CARDINALITY function in 10g now makes it trivial to count the elements of a collection in SQL. This function is logically equivalent to the COUNT pseudo-method. In the following examples we'll show simple examples of the function's usage in both PL/SQL and SQL.

DECLARE
TYPE
varchar2_ntt IS TABLE OF VARCHAR2(2000);
nt varchar2_ntt;
BEGINnt := varchar2_ntt( 'A','B','C','C');DBMS_OUTPUT.PUT_LINE( 'Count = ' || nt.COUNT );DBMS_OUTPUT.PUT_LINE( 'Cardinality = ' || CARDINALITY(nt) );END;/Count = 4
Cardinality = 4
PL/SQL procedure successfully completed.

No comments:

Post a Comment