Varray Example

DECLARE
–– Define a varray with a maximum of 3 rows.
TYPE integer_varray IS VARRAY(3) OF INTEGER;
–– Declare the varray with null values.
varray_integer INTEGER_VARRAY := integer_varray(NULL,NULL,NULL);
BEGIN
— Print initialized null values.
dbms_output.put_line(‘Varray initialized as nulls.’);
dbms_output.put_line(‘––––––––––––––————–‘);
FOR i IN 1..3 LOOP

dbms_output.put (‘Integer Varray [‘||i||’] ‘);
dbms_output.put_line(‘[‘||varray_integer(i)||’]’);
END LOOP;
–– Assign values to subscripted members of the varray.
varray_integer(1) := 11;
varray_integer(2) := 12;
varray_integer(3) := 13;

— Print initialized null values.
dbms_output.put (CHR(10)); –- Visual line break.
dbms_output.put_line(‘Varray initialized as values.’);
dbms_output.put_line(‘––-––––––––––––————–‘);
FOR i IN 1..3 LOOP
dbms_output.put_line(‘Integer Varray [‘||i||’] ‘
|| ‘[‘||varray_integer(i)||’]’);
END LOOP;
END;
/

The syntax of defining varray as an object in database is:

CREATE OR REPLACE TYPE type_name AS {VARRAY | VARYING ARRAY} (size_limit)
OF element_type [ NOT NULL ];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s