0% found this document useful (0 votes)
34 views2 pages

Collections

This document contains examples demonstrating various properties and methods of PL/SQL variable arrays (varray) and nested tables. The examples show how to: 1) Declare a varray type and initialize a varray variable, then use COUNT and LIMIT to view the initialized size and maximum limit. 2) Initialize a varray with more elements than originally declared and use COUNT to view the populated size. Also initialize a nested table and use COUNT. 3) Use EXTEND to dynamically increase the size of a varray and nested table, then add elements to the extended positions. 4) Use EXISTS to check if a specific element exists in a varray.

Uploaded by

Oscar Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Collections

This document contains examples demonstrating various properties and methods of PL/SQL variable arrays (varray) and nested tables. The examples show how to: 1) Declare a varray type and initialize a varray variable, then use COUNT and LIMIT to view the initialized size and maximum limit. 2) Initialize a varray with more elements than originally declared and use COUNT to view the populated size. Also initialize a nested table and use COUNT. 3) Use EXTEND to dynamically increase the size of a varray and nested table, then add elements to the extended positions. 4) Use EXISTS to check if a specific element exists in a varray.

Uploaded by

Oscar Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LIMIT

SQL> DECLARE
2
TYPE numberVarray IS VARRAY(10)OF NUMBER;
3
4
v_numarray numberVarray :=numberVarray(10,20,30);
5
6 BEGIN
7
8
DBMS_OUTPUT.PUT_LINE('Varray Count = '||
TO_CHAR(v_numarray.COUNT));
9
10
DBMS_OUTPUT.PUT_LINE('Varray Limit = '||
TO_CHAR(v_numarray.LIMIT));
11 END;
12 /
Varray Count = 3
Varray Limit = 10
PL/SQL procedure successfully completed.
COUNT
SQL> DECLARE
2
TYPE numberVarray IS VARRAY(10)OF NUMBER;
3
4
v_numarray numberVarray :=numberVarray(10,20,30,40,50);
5
6
TYPE numberTableType IS TABLE OF NUMBER;
7
8
v_numlist numberTableType :=numberTableType(101,201,301,401);
9
10 BEGIN
11
12
DBMS_OUTPUT.PUT_LINE('Varray Count = '||
TO_CHAR(v_numarray.COUNT));
13
14
DBMS_OUTPUT.PUT_LINE('Nested Table Count = '||
TO_CHAR(v_numlist.COUNT));
15 END;
16 /
Varray Count = 5
Nested Table Count = 4
PL/SQL procedure successfully completed.

EXTEND
SQL>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

DECLARE
TYPE numberVarray IS VARRAY(10)OF NUMBER;
v_numarray numberVarray :=numberVarray(NULL,NULL);
TYPE numberTableType IS TABLE OF NUMBER;
v_numlist numberTableType :=numberTableType(NULL);
BEGIN
v_numarray(1):=1001;
v_numarray(2):=1002;
v_numarray.EXTEND;
v_numarray(3):=1003;
v_numlist(1):=101;
v_numlist.EXTEND(5);
v_numlist(5):=105;
END;
/

EXISTS
SQL> DECLARE
2
TYPE numberVarray IS VARRAY(5)OF NUMBER;
3
4
v_numarray numberVarray :=numberVarray(10,20,30,40,50);
5
6 BEGIN
7
8
IF v_numarray.EXISTS(4) THEN
9
10
DBMS_OUTPUT.PUT_LINE('The element 4 exists in the variable a
rray.');
11
12
END IF;
13
14 END;
15 /
The element 4 exists in the variable array.
PL/SQL procedure successfully completed.

You might also like