A Relational Table with Object Types (Cont.)


Populating Relational Tables with Object Types
The following example shows how to insert records into the customer table and list the table contents:

 SQL> INSERT INTO  customer  VALUES (101,
   2    address_typ('715 40th St.,', '#202J', 'Grand Forks', 'ND', '58203') );

 1 row created.

 SQL> INSERT INTO  customer  VALUES (102,
   2    address_typ('University Ave.', 'CS Dept', 'Grand Forks', 'ND', '58202') );

 1 row created.

 SQL> SELECT * FROM  customer c  WHERE  c.id = 101;

  ID          CUST_ADDRESS(ADDRESS1, ADDRESS2, CITY, STATE, ZIP)
 ----  --------------------------------------------------------------------
 101   ADDRESS_TYP('715 40th St.,', '#202J', 'Grand Forks', 'ND', '58203')

Resolving Names for Attributes
Name resolution of object type attributes is similar to the resolution of column names in Oracle relational tables.

 SQL> SELECT  c.cust_address.city  FROM  customer c;

 CUST_ADDRESS.CIT
 ----------------
 Grand Forks
 Grand Forks

Any attribute names used are associated with the current object instance being pointed to by the SQL statement. Consider the customer table example:


      “The man of knowledge must be able not only to love his enemies but also to hate his friends.”    
      ― Friedrich Nietzsche