Oracle implements Objects through the use of TYPEs, defined in a similar way to packages.
Unlike packages in which the instance of the package is limited to the current session, an instance of an object type can be stored in the database for later use. The definition of the type contains a comma separated list of attributes and properties, defined in the same way as
- package variables, and
- member functions or procedures.
If a type contains member functions or procedures, the procedural work for these elements is defined in the TYPE BODY.
To see how objects can be used, suppose an object is created to represent a person. In this case, a person is defined by three attributes: first_name, last_name and date_of_birth.
Returning the age of the person is also desired, so this is included as a member function, get_age.
CREATE OR REPLACE TYPE t_person AS OBJECT (
MEMBER FUNCTION get_age RETURN NUMBER