Creating Object Types: Syntax
Object Type
It is an Oracle database construct, managed via DDL extensions, that defines a data structure (attributes) and the legal operations (methods) on the attributes.
The type is only a template and holds no data itself; you may create variables, tables, columns, and other constructs of this type.
Attribute
It is a structural part of an object, roughly akin to a column in a table.
- Each attribute must be of a single datatype, either scalar, like
VARCHAR2
or INTEGER
, or composite, like a user-defined nested table.
- User-defined types must have one or more attributes.
- Attributes are named and have a datatype.
- Attribute names must be unique within a user-defined datatype definition.
- Attribute datatypes can be an object type or a built-in datatype.
Method
It is a procedure or function that operates on an object’s attributes.
- The methods for an object can only be invoked in the context of a specific object of that type.
- There is a special default method supplied by Oracle, a constructor, that initializes objects.
- Method implementation may be coded in PL/SQL or in a 3 GL such as Java and C/C++ and being invoked as an Oracle “external procedure.”
- Methods are similar to Oracle functions, procedures, and packages.