The COUNT function returns the number of members in a VARRAY.
SQL>
SQL> CREATE OR REPLACE TYPE mem_type IS VARRAY(10) of VARCHAR2(15)
2 /
Type created.
SQL>
SQL> CREATE TABLE club (Name VARCHAR2(10),
2 Address VARCHAR2(20),
3 City VARCHAR2(20),
4 Phone VARCHAR2(8),
5 Members mem_type)
6 /
Table created.
SQL>
SQL> INSERT INTO club VALUES ('AL','111 First St.','Mobile',
2 '222-2222', mem_type('Brenda','Richard'));
1 row created.
SQL>
SQL> INSERT INTO club VALUES ('FL','222 Second St.','Orlando',
2 '333-3333', mem_type('Gen','John','Steph','JJ'));
1 row created.
SQL>
SQL> CREATE OR REPLACE PROCEDURE vartest IS
2 CURSOR fcur IS
3 SELECT city, members FROM club;
4 BEGIN
5 FOR j IN fcur LOOP
6 IF j.members.exists(1) THEN
7 dbms_output.put_line(j.City||' has '|| j.members.count||' members');
8
9 END IF;
10 END LOOP; /* end for j in fcur loop */
11 END vartest;
12 /
Procedure created.
SQL> exec vartest;
Mobile has 2 members
Orlando has 4 members
PL/SQL procedure successfully completed.
SQL>
SQL> drop table club;
Table dropped.
SQL> drop type mem_type;
Type dropped.
SQL>