Object type

From Oracle FAQ
Jump to: navigation, search

The object-relational model allows users to define object types which specify both the structure of the data and the methods of operating on the data.

Object types were first introduced with Oracle 8.

Example[edit]

Create a new object type with a member function (defined in the type body):

CREATE TYPE employee_type as OBJECT (
         name            varchar2(30),
         ssn             varchar2(11),
         salary          number),
    MEMBER FUNCTION get_id RETURN number);

  CREATE TYPE BODY emp_type (
          MAP MEMBER FUNCTION get_id RETURN number is
              BEGIN
                 RETURN ascii_to_num(ssn);
              END;);

Create a table based on the above type:

  CREATE TABLE emp OF employee_type;