One-step INSERTs into a Table that Contains Row Objects : Object Table « Object Oriented « Oracle PL/SQL Tutorial






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);

Table created.

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

SQL>
SQL> INSERT INTO client
  2  SELECT 'Walsh', REF(aa)
  3  FROM address_table aa
  4  WHERE zip = '32563';

0 rows created.

SQL>
SQL> SELECT name, DEREF(address)
  2  FROM client;

no rows selected

SQL>
SQL>
SQL> select * from client;

no rows selected

SQL>
SQL> --DEREF (Dereference) the Row Addresses
SQL> SELECT name, DEREF(address)
  2  FROM client;

no rows selected

SQL>
SQL>
SQL> drop table address_table;

Table dropped.

SQL> drop table client;

Table dropped.

SQL>
SQL> drop type addressType;

Type dropped.








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