Using a Nested Table Type to Define a Column in a Table : Nested Table Column « Collections « Oracle PL/SQL Tutorial






Once you have defined your nested table type, you can use it to define a column in a table.

The NESTED TABLE clause identifies the name of the nested table column (addresses).

The STORE AS clause specifies the name of the actual nested table (nested_addresses).

You cannot access the nested table independently of the table in which it is embedded.

SQL>
SQL> CREATE Or Replace TYPE AddressType AS OBJECT (
  2    street VARCHAR2(15),
  3    city   VARCHAR2(15),
  4    state  CHAR(2),
  5    zip    VARCHAR2(5)
  6  );
  7  /

SQL>
SQL> CREATE Or Replace TYPE nested_table_AddressType AS TABLE OF AddressType;
  2  /

Type created.

SQL>
SQL> CREATE TABLE employee (
  2    id         INTEGER PRIMARY KEY,
  3    first_name VARCHAR2(10),
  4    last_name  VARCHAR2(10),
  5    addresses  nested_table_AddressType
  6  )
  7  NESTED TABLE
  8    addresses
  9  STORE AS
 10    nested_addresses;

Table created.

SQL>
SQL> desc employee;
 Name           Null?    Type

 ID             NOT NULL NUMBER(38)
 FIRST_NAME              VARCHAR2(10)
 LAST_NAME               VARCHAR2(10)
 ADDRESSES               NESTED_TABLE_ADDRESSTYPE
   STREET                VARCHAR2(15)
   CITY                  VARCHAR2(15)
   STATE                 CHAR(2)
   ZIP                   VARCHAR2(5)

SQL>
SQL> drop table employee;

Table dropped.








26.9.Nested Table Column
26.9.1.Using a Nested Table Type to Define a Column in a Table
26.9.2.Getting Information on Nested Tables
26.9.3.Set the depth to 2 and describe a nested table
26.9.4.Populating a Nested Table with Elements
26.9.5.Selecting Nested Table Elements
26.9.6.Modifying Nested Table Elements
26.9.7.Update the first record in the nested table.
26.9.8.Delete one record in the nested table