The option to group values is an advantage, because the many individual columns in an SQL query no longer have to be listed.
Creating Abstract Data Types (ADTs) also allows us to embed new constructs such as object ID (OIDs) and VARRAYs in table columns.
Embedded constructs have a huge impact on Oracle performance, since expensive JOINS can be avoided.
An Abstract Data Type (ADT) consists of a data structure and subprograms that manipulate the data. The variables that form the data structure are called attributes. The subprograms that manipulate the attributes are called methods. ADTs are stored in the database and instances of ADTs can be stored in tables and used as PL/SQL variables. ADTs let you reduce complexity by separating a large system into logical components, which you can reuse.
- In the static data dictionary view *_OBJECTS, the OBJECT_TYPE of an ADT is TYPE.
- In the static data dictionary view *_TYPES, the TYPECODE of an ADT is OBJECT.
The CREATE TYPE statement creates or replaces the specification of one of these:
- Abstract Data Type (ADT) (including a SQLJ object type)
- Standalone stored varying array (varray) type
- Standalone stored nested table type
- Incomplete object type
An incomplete type is a type created by a forward type definition. It is called incomplete because it has a name but no attributes or methods. It can be referenced by other types, allowing you define types that refer to each other. However, you must fully specify the type before you can use it to create a table or an object column or a column of a nested table type. The CREATE TYPE statement specifies the name of the type and its attributes, methods, and other properties. The CREATE TYPE BODY statement contains the code for the methods that implement the type.
Notes:
- If you create a type whose specification declares only attributes but no methods, then you need not specify a type body.
- If you create a SQLJ object type, then you cannot specify a type body. The implementation of the type is specified as a Java class.
- A standalone stored type that you create with the CREATE TYPE statement differs from a type that you define in a PL/SQL block or package.
- With the CREATE TYPE statement, you can create nested table and VARRAY types, but not associative arrays. In a PL/SQL block or package, you can define all three collection types.
The next lesson shows how to imbed an OID in a table.