INSERT Values into a Table that Contains Row Objects (TCRO) : Object Table « Object Oriented « Oracle PL/SQL Tutorial






One way to begin is to insert into the client table and null the addressType:

SQL>
SQL>
SQL> CREATE OR REPLACE TYPE addressType as OBJECT(
  2  street VARCHAR2(20),
  3  city VARCHAR2(20),
  4  state CHAR(2),
  5  zip CHAR(5))
  6  /

Type created.

SQL>
SQL> CREATE TABLE address_table OF addressType
  2  /

Table created.

SQL>
SQL> CREATE TABLE client (name VARCHAR2(20),
  2    address REF addressType scope is address_table)
  3  /

Table created.

SQL>
SQL> DESC client;
 Name          Null?    Type
 ----------
 NAME                   VARCHAR2(20)
 ADDRESS                REF OF ADDRESSTYPE

SQL>
SQL> INSERT INTO client VALUES ('Jones',null);

1 row created.

SQL>
SQL>
SQL> SELECT *
  2  FROM client;

NAME                 ADDRESS
-------------------- --------------------------------------------------
Jones

SQL>
SQL>
SQL> drop table address_table;

Table dropped.

SQL> drop table client;

Table dropped.

SQL>
SQL> drop type addresstype;

Type dropped.

SQL>








32.9.Object Table
32.9.1.You can also use an object type to define an entire table, and the table is known as an object table.
32.9.2.Inserting a row into an object table
32.9.3.One-step INSERTs into a Table that Contains Row Objects
32.9.4.INSERT Values into a Table that Contains Row Objects (TCRO)
32.9.5.Insert data just as one would ordinarily do with a common SQL table:
32.9.6.SELECTing Individual Columns in Table that Contains Row Objects
32.9.7.Selecting Rows from the object Table
32.9.8.SELECT from the object-oriented table
32.9.9.Updating a Row in the object Table
32.9.10.UPDATE a Table that Contains Row Objects (TCRO)
32.9.11.Accessing the object table by reference
32.9.12.Create a table based on an Object with methods
32.9.13.Alter table to add a user-defined type column