A Relational Table with Object Types


You can create a user-defined datatype and then use the new datatype in a relational table. The data actually resides as column values in the table, rather than the column value being a pointer (REF) to the data.

This methodology creates a column object or nested object that
01SQL> CREATE TYPE  address_typ  AS OBJECT (
02  2    address1   VARCHAR2(32),
03  3    address2   VARCHAR2(32),
04  4    city       VARCHAR2(16),
05  5    state      CHAR(2),
06  6    zip        CHAR(5) );
07 
08Type created.
09 
10SQL> CREATE TABLE  customer (
11  2    id            INTEGER PRIMARY KEY,
12  3    cust_address  address_typ );
13 
14Table created.


The address_typ type is used as the datatype for the cust_address column of a customer relational table. When object types are instantiated in this way, you create a column object or nested object. If the user-defined type is in another schema, you must use the schema name as a qualifier of the datatype. For example, if user scott owns scotts_typ object, use:
   CREATE TABLE  my_table( x scott.scotts_typ );