Creating Object Types


Four categories of user-defined types are (i) simple, (ii) composite, (iii) cyclic, and (iv) collection.

Declaring a Simple Type
The example below declares a simple type because it uses only attributes based on built-in types:
 CREATE TYPE  person_typ  AS OBJECT (
   name  VARCHAR(64),
   SSN   INTEGER,
   DOB   DATE );

Creating a Composite User-Defined Type
Once you create a type, you can use it to create another user-defined type. The composite user-defined type has at least one attribute of a user-defined type. This type must have been created previously.

 CREATE TYPE  sales_rep_typ  AS OBJECT (
   pers_info   person_typ,
   territory   NUMBER(5) );

The composite type is dependent on the included type. In order to modify the person_typ, you must drop the sales_rep_typ type first.




      “Knowing others is intelligence;    
      knowing yourself is true wisdom.    
      Mastering others is strength;    
      mastering yourself is true power.”    
      ― Lao Tzu, Tao Te Ching