Reference column : Object Reference Column « Object Oriented « Oracle PL/SQL Tutorial






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>
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> SELECT *
  2  FROM client;

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

SQL>
SQL>
SQL> UPDATE client SET address =
  2  (SELECT REF(aa)
  3  FROM address_table aa
  4  WHERE aa.city LIKE 'Mob%')
  5  WHERE name = 'Jones'
  6
SQL> select * from client;

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

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

NAME
--------------------
DEREF(ADDRESS)(STREET, CITY, STATE, ZIP)
-----------------------------------------
Jones



SQL>
SQL>
SQL> drop table address_table;

Table dropped.

SQL> drop table client;

Table dropped.

SQL>
SQL> drop type addresstype;

Type dropped.

SQL>
SQL>








32.8.Object Reference Column
32.8.1.Object References and Object Identifiers
32.8.2.CREATE a Table that References Our Row Objects
32.8.3.Inserting a Row into the Object Reference table
32.8.4.You can access this object identifier using the REF() function and store the returned objectifier in a REF column.
32.8.5.Selecting a Row from the Object reference table
32.8.6.You can access the rows in the object tables that are pointed to by REF column values using t REF() function; this function accepts a REF column as a parameter.
32.8.7.Updating a Row in the object reference table
32.8.8.Reference column