Object type as column type Object type as row type Type CUSTOMER_OBJTYP Collection types - Array type Collection types – Nested table

7.1 Theoretical Background

Here are some examples of Oracle 9i types DDL statement, which are mapped from object-relational data model.

7.1.1 Object type as column type

Type NAME_OBJTYP firstName midName lastName VARCHAR215 VARCHAR215 VARCHAR215 CREATE TYPE name_objtyp AS OBJECT firstName VARCHAR215, midName VARCHAR215, lastName VARCHAR215; Type ADDRESS_OBJTYP street City state poscode VARCHAR215 VARCHAR210 VARCHAR210 NUMBER CREATE TYPE address_objtyp AS OBJECT street VARCHAR215, city VARCHAR210, state VARCHAR210, poscode number; 48

7.1.2 Object type as row type Type CUSTOMER_OBJTYP

custNo custName CustAdd ress VARCHAR215 Name_objtyp Address _objtyp CREATE TYPE customer_objtyp AS OBJECT CustNo VARCHAR215, CustName name_objtyp, CustAddress address_objtyp; CREATE TABLE customer_tab of customer_objtyp CustNo PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY;

7.1.3 Collection types - Array type

Type PHONELIST_VARTYP PhoneNum Maximum 5 values VARCHAR215 CREATE TYPE phonelist_vartyp AS VARRAY 5 OF VARCHAR220; Modification needs to be made for CUSTOMER_OBJTYP to include the new array type. Type CUSTOMER_OBJTYP custNo custName CustAddress custContact VARCHAR215 Name_objtyp Address_objtyp Phonelist_vartyp CREATE TYPE customer_objtyp AS OBJECT CustNo VARCHAR215, CustName name_objtyp, CustAddress address_objtyp, CustContact Phonelist_vartyp; CREATE TABLE customer_tab of customer_objtyp CustNo PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY; 49 Inserting values into customer_tab Example : INSERT INTO customer_tab VALUES‘C001’, name_objtyp‘Mohd’,’Azmi’,’Ali’, address_objtyp‘Jln Merbau’,’Ayer Keroh’,’Melaka’,75450, Phonelist_vartyp‘012-8792345’,’06-5645345’;

7.1.4 Collection types – Nested table

Type DEPENDANT_OBJTYP DependantId PK dependantName dependantAddress String Object Type Object Type VARCHAR210 NAME_OBJTYP ADDRESS_OBJTYP CREATE TYPE dependant_objtyp AS OBJECT dependantId VARCHAR210, dependantName name_objtyp, dependantAddress address_objtyp; Column dependantList of DEPENDANT_NESTEDTAB as table of DEPENDANT_OBJTYP dependantId dependantName dependantAddress VARCHAR210 NAME_OBJTYP ADDRESS_OBJTYP CREATE TYPE dependant_nestedtab AS TABLE OF dependant_objtyp; Type EMPLOYEE_OBJTYP EmployeeId PK startDate dependantList String Date Nested Table VARCHAR210 DATE DEPENDANT_NESTEDTAB CREATE TYPE employee_objtyp AS OBJECT EmployeeId VARCHAR210, StartDate DATE, DependantList DEPENDANT_NESTEDTAB; 50 Then, create object table based on object type created for employee. CREATE TABLE employee_tab of employee_objtyp EmployeeId PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY NESTED TABLE DependantList STORE AS DependantListStorageTable PRIMARY KEY NESTED_TABLE_ID,dependantId ; OR CREATE TABLE employee_tab of employee_objtyp PRIMARY KEY EmployeeId OBJECT IDENTIFIER is PRIMARY KEY NESTED TABLE DependantList STORE AS DependantListStorageTable PRIMARY KEY NESTED_TABLE_ID, dependantId ; Inserting values into employee_tab INSERT INTO employee_tab VALUES E001,SYSDATE,DEPENDANT_NESTEDTAB; The values for nested table in the DependantList column need to be inserted. INSERT INTO TABLE SELECT e.dependantList FROM employee_tab e WHERE e.employeeId = ’E001’ VALUES ‘D101’, name_objtyp‘Nur’,’Ainun’,’Anas’, address_objtyp‘Jln 120’,’Jasin’,’Melaka’,75450; 51

7.1.5 REF type