HOWTO USE PLSQL VARRAY IN SHORT

PLSQL Collections are not as much used as Java Collections. Below a short example of most of the futures of VARRAY collection type.

</div>
<div>DECLARE
TYPE VARRTYPE IS VARRAY(10) OF NUMBER;
v1 VARRTYPE;
v2 VARRTYPE := VARRTYPE(0,1,2,3,4,5,6,7,8,9);
v3 VARRTYPE;
BEGIN
v1 := NEW VARRTYPE();
v3 := NEW VARRTYPE();v3.extend(5);
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------');
for l in 1..5
LOOP
v3(l) := l * 100;
DBMS_OUTPUT.PUT_LINE('loop: ' || l || ' v3 count: ' || v3.COUNT || ' limit: ' || v3.LIMIT || ' first: ' || v3.FIRST || ' last: ' || v3.LAST || ' prior(): ' || v3.PRIOR(l) || ' next(): ' || v3.NEXT(l));
END LOOP;DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------');
for l in 1..10
LOOP
v1.EXTEND();
v1(l) := l * 100;
DBMS_OUTPUT.PUT('loop: ' || l || ' v1 count: ' || v1.COUNT || ' limit: ' || v1.LIMIT || ' first: ' || v1.FIRST || ' last: ' || v1.LAST || ' prior(): ' || v1.PRIOR(l) || ' next(): ' || v1.NEXT(l));

IF v1.EXISTS(l) THEN
DBMS_OUTPUT.PUT_LINE(' v1 element: ' || l || ' exists: ');
END IF;
END LOOP;

DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------');
v1.TRIM(1); -- delete 1 element from the end
DBMS_OUTPUT.PUT_LINE(' v1 count: ' || v1.COUNT || ' limit: ' || v1.LIMIT || ' first: ' || v1.FIRST || ' last: ' || v1.LAST );
DBMS_OUTPUT.PUT_LINE('-------------------------------------------------------------');

Advertisements