SET ECHO ON SET SERVEROUTPUT ON SET ARRAYSIZE 1 -- -- plsql09.txt -- -- Simple PL/SQL demo of a varray DECLARE TYPE dVarray_type IS VARRAY (100) OF VARCHAR2(64); -- I could Construct the VARRAY here if I want but I just declare it dVarray1 dVarray_type; -- Construction syntax for the DECLARE section dVarray2 dVarray_type := dVarray_type('a','b'); dVarray3 dVarray_type; BEGIN dVarray3 := dVarray2; -- It is easy to copy into an un-constructed array dVarray1 := dVarray_type('x'); -- Construct the VARRAY -- dVarray1(0) := 'y'; -- syntax error. Subscript starts at 1 dVarray1(1) := 'y'; -- dVarray1(2) := 'z'; -- syntax error. VARRAY constructed with only 1 element -- Use EXTEND method to make room dVarray1.EXTEND; dVarray1(2) := 'z'; -- dVarray1(3) := 'a'; -- syntax error. EXTEND only adds one space -- Useful navigation techniques dbms_output.put_line( dVarray1(1) ); dbms_output.put_line( dVarray1.FIRST ); dbms_output.put_line( dVarray1.LAST ); FOR i IN dVarray3.FIRST.. dVarray3.LAST LOOP dbms_output.put_line( dVarray3(i) ); END LOOP; END; / -- End of demo