REF type Type inheritance

7.1.5 REF type

REF type is used to show associationrelationship between objects. Type SYSTEM_OBJTYP SName PK minAge VARCHAR215 INTEGER CREATE TYPE system_objtyp AS OBJECT sname VARCHAR215, minAge INTEGER ; Then, create an object table for System. CREATE TABLE system_tab OF system_objtyp sname PRIMARY KEY OBJECT IDENTIFIER PRIMARY KEY; Type SERIES_OBJTYP SrsName PK theme inSys VARCHAR215 INTEGER system_objtyp CREATE TYPE series_objtyp AS OBJECT srsname VARCHAR215, theme INTEGER, inSys REF system_objtyp ; Then, create an object table for Series. CREATE TABLE series_tab OF series_objtyp PRIMARY KEY srsname, FOREIGN KEY inSys REFERENCES system_tab OBJECT IDENTIFIER IS PRIMARY KEY; 52 Inserting values into system_tab Values for values need to be inserted prior to insertion of child table. INSERT INTO system_tab VALUES‘UNIX’,4; Then, insert values for child table. INSERT INTO series_tab SELECT ‘VS400’,1200,REFs FROM system_tab s WHERE s.sname=’UNIX’; OR INSERT INTO series_tab VALUES ‘VS400’,1200, SELECT REFs FROM system_tab s WHERE s.sname=’UNIX’; SCOPE FOR constraint on a REF is not allowed in CREATE TABLE statement. Therefore, to ensure that inSys attribute in series_tab table can reference only object table system_tab, issue the following ALTER TABLE statement on series_tab table. ALTER TABLE series_tab ADDSCOPE FORinSys IS system_tab; 53

7.1.6 Type inheritance

Oracle 9i allows type inheritance as what is provided by SQL3. With this facility, a subtype can be created under a base type only if the base type allows subtypes. This is based on FINAL property of type. By default, all new types are created as FINAL. FINAL clause indicates that particular type is the last of the series and cannot have subtypes defined under it. To enable subtype creation, one must specify NOT FINAL clause in CREATE TYPE statement. Example : CREATE TYPE person_ObjTyp AS OBJECT Name VARCHAR230, Contact VARCHAR29 NOT FINAL; CREATE TYPE student_ObjTyp UNDER person_ObjTyp StudentId VARCHAR230 NOT FINAL; CREATE TABLE PERSON OF person_ObjTyp name PRIMARY KEY OBJECT IDENTIFIER IS PRIMARY KEY; Inserting values into person INSERT INTO person VALUES StudentTyp‘Maria Ibrahim’,’06-356788’,’s001’;

7.2 Exercise