Populating a Varray with Elements : VARRAY Column « Collections « Oracle PL/SQL Tutorial






You can populate the elements in a varray using an INSERT statement.

SQL>
SQL>
SQL> CREATE Or Replace TYPE addressVarray AS VARRAY(2) OF VARCHAR2(50);
  2  /

Type created.

SQL> CREATE TABLE employee (
  2    id         INTEGER PRIMARY KEY,
  3    first_name VARCHAR2(10),
  4    last_name  VARCHAR2(10),
  5    addresses  addressVarray
  6  );

Table created.

SQL>
SQL> DESCRIBE employee;
 Name            Null?    Type

 ID              NOT NULL NUMBER(38)
 FIRST_NAME               VARCHAR2(10)
 LAST_NAME                VARCHAR2(10)
 ADDRESSES                ADDRESSVARRAY

SQL>
SQL> INSERT INTO employee VALUES (
  2    1, 'Steve', 'Brown',
  3    addressVarray(
  4      'AAAAAAAAAAAAAAAA',
  5      'BBBBBBBBBBBBBBBB'
  6    )
  7  );

1 row created.

SQL>
SQL> SELECT *
  2  FROM employee;

ID FIRST_NAME LAST_NAME           ADDRESSES
----------------------------------------------------------------------------------------
1 Steve      Brown                ADDRESSVARRAY('AAAAAAAAAAAAAAAA', 'BBBBBBBBBBBBBBBB')


SQL>
SQL>
SQL> drop table employee;

Table dropped.

SQL>
SQL>








26.3.VARRAY Column
26.3.1.Stored VARRAYS
26.3.2.Using a Varray Type to Define a Column in a Table
26.3.3.Display the structure of a table with a valarray column
26.3.4.Populating a Varray with Elements
26.3.5.Selecting Varray Elements
26.3.6.Modifying Varray Elements
26.3.7.Set empty varray value
26.3.8.Define function to get the first value in varray
26.3.9.Insert on whole VARRAYS
26.3.10.UPDATE on varray column in PL/SQL block
26.3.11.UPDATE on varray column
26.3.12.DELETE on varray column
26.3.13.SELECT into with varray column