| Oracle8i SQL Reference Release 2 (8.1.6) A76989-01 |
|
SQL Statements (continued), 3 of 10
create_incomplete_type::=
element_list::=
procedure_spec | function_spec::=
Java_declaration::=
C_declaration::=
To create an object type, named varying array (varray), nested table type, or an incomplete object type.
Oracle implicitly defines a constructor method for each user-defined type that you create. A constructor is a system-supplied procedure that is used in SQL statements or in PL/SQL code to construct an instance of the type value. The name of the constructor method is the same as the name of the user-defined type.
The parameters of the object type constructor method are the data attributes of the object type. They occur in the same order as the attribute definition order for the object type. The parameters of a nested table or varray constructor are the elements of the nested table or the varray.
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, and so can be used to 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.
|
See Also:
PL/SQL User's Guide and Reference, Oracle8i Application Developer's Guide - Fundamentals, and Oracle8i Concepts for more information about objects, incomplete types, varrays, and nested tables. |
To create a type in your own schema, you must have the CREATE TYPE system privilege. To create a type in another user's schema, you must have the CREATE ANY TYPE system privilege. You can acquire these privileges explicitly or be granted them through a role.
The owner of the type must either be explicitly granted the EXECUTE object privilege in order to access all other types referenced within the definition of the type, or the type owner must be granted the EXECUTE ANY TYPE system privilege. The owner cannot obtain these privileges through roles.
If the type owner intends to grant other users access to the type, the owner must be granted the EXECUTE object privilege to the referenced types with the GRANT OPTION or the EXECUTE ANY TYPE system privilege with the ADMIN OPTION. Otherwise, the type owner has insufficient privileges to grant access on the type to other users.
|
|
re-creates the type if it already exists. Use this clause to change the definition of an existing type without first dropping it. |
|
|
|
Users previously granted privileges on the re-created object type can use and reference the object type without being granted privileges again.
If any function-based indexes depend on the type, Oracle marks the indexes |
|
|
schema |
is the schema to contain the type. If you omit schema, Oracle creates the type in your current schema. |
|
|
type_name |
is the name of an object type, a nested table type, or a varray type.
If creating the type results in compilation errors, Oracle returns an error. You can see the associated compiler error messages with the SQL*Plus command |
|
|
create_object_type |
creates the type as a user-defined object type. The variables that form the data structure are called attributes. The member subprograms that define the object's behavior are called methods. |
|
|
invoker_rights_clause |
specifies whether the member functions and procedures of the object type execute with the privileges and in the schema of the user who owns the object type or with the privileges and in the schema of This clause also determines how Oracle resolves external names in queries, DML operations, and dynamic SQL statements in the member functions and procedures of the type. Restriction: You can specify this clause only for an object type, not for a nested table or varray type. See Also: PL/SQL User's Guide and Reference. |
|
|
|
|
specifies that the member functions and procedures of the object type execute with the privileges of
This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of |
|
|
|
specifies that the member functions and procedures of the object type execute with the privileges of the owner of the schema in which the functions and procedures reside, and that external names resolve in the schema where the member functions and procedures reside. This is the default. |
|
datatype |
is the name of the attribute's Oracle built-in datatype or user-defined type. For a list of possible datatypes, see "Datatypes". Restrictions:
|
|
|
attribute |
specifies, for an object type, the name of an object attribute. Attributes are data items with a name and a type specifier that form the structure of the object. You must specify at least one attribute for each object type. |
|
|
|
specifies a function or procedure subprogram associated with the object type that is referenced as an attribute. Typically, you invoke member methods in a "selfish" style, such as |
|
|
|
also specifies a function or procedure subprogram associated with the object type. However, unlike member methods, static methods do not have any implicit parameters (that is, SELF is not referenceable in their body). They are typically invoked as |
|
|
For both member and static methods, you must specify a corresponding method body in the object type body for each procedure or function specification. See "CREATE TYPE BODY". For information about method invocation and methods, see PL/SQL User's Guide and Reference. |
||
|
procedure_spec | function_spec |
is the specification of a procedure or function subprogram. The
If this subprogram does not include the declaration of the procedure or function, you must issue a corresponding For a list of restrictions on user-defined functions, see "Restrictions on User-Defined Functions". |
|
|
call_spec |
is the call specification ("call spec") that maps a Java or C method name, parameter types, and return type to their SQL counterparts. If all the member methods in the type have been defined in this clause, you need not issue a corresponding |
|
|
|
In Java_declaration, 'string' identifies the Java implementation of the method. See Also:
|
|
|
pragma_clause |
specifies a compiler directive. |
|
|
|
is a compiler directive that denies member functions read/write access to database tables, packaged variables, or both, and thereby helps to avoid side effects. See Also: Oracle8i Application Developer's Guide - Fundamentals. |
|
|
|
method_name |
is the name of the |
|
|
|
specifies that the pragma should be applied to all methods in the type for which a pragma has not been explicitly specified. |
|
|
|
specifies the constraint writes no database state (does not modify database tables). |
|
|
|
specifies the constraint writes no package state (does not modify packaged variables). |
|
|
|
specifies the constraint reads no database state (does not query database tables). |
|
|
|
specifies the constraint reads no package state (does not reference packages variables). |
|
|
|
specifies that the restrictions listed in the pragma are not actually to be enforced, but are simply trusted to be true. |
|
|
specifies a member function (map method) that returns the relative position of a given instance in the ordering of all instances of the object. A map method is called implicitly and induces an ordering of object instances by mapping them to values of a predefined scalar type. PL/SQL uses the ordering to evaluate Boolean expressions and to perform comparisons. |
|
|
|
If the argument to the map method is null, the map method returns null and the method is not invoked. |
|
|
|
An object specification can contain only one map method, which must be a function. The result type must be a predefined SQL scalar type, and the map function can have no arguments other than the implicit |
|
|
|
Note: If type_name will be referenced in queries involving sorts (through an |
|
|
|
specifies a member function ( |
|
|
|
If either argument to the order method is null, the order method returns null and the method is not invoked.
When instances of the same object type definition are compared in an |
|
|
|
An object specification can contain only one |
|
|
You can define either a MAP method or an ORDER method in a type specification, but not both. If you declare either method, you can compare object instances in SQL. |
||
|
If neither a |
||
|
Use See Also: Oracle8i Application Developer's Guide - Fundamentals for more information about object value comparisons. |
||
|
create_varray_type |
creates the type as an ordered set of elements, each of which has the same datatype. You must specify a name and a maximum limit of zero or more. The array limit must be an integer literal. Oracle does not support anonymous varrays. |
|
|
|
The type name for the objects contained in the varray must be one of the following: |
|
|
|
Restrictions: |
|
|
create_nested_table_type |
creates a named nested table of type datatype. When datatype is an object type, the nested table type describes a table whose columns match the name and attributes of the object type. When datatype is a scalar type, then the nested table type describes a table with a single, scalar type column called "column_value". |
|
|
|
Restrictions: |
|
The following example creates object type PERSON_T with LOB attributes:
CREATE TYPE person_t AS OBJECT (name CHAR(20), resume CLOB, picture BLOB);
The following statement creates MEMBERS_TYPE as a varray type with 100 elements:
CREATE TYPE members_type AS VARRAY(100) OF CHAR(5);
The following example creates a named table type PROJECT_TABLE of object type PROJECT_T:
CREATE TYPE project_t AS OBJECT (pno CHAR(5), pname CHAR(20), budgets DEC(7,2)); CREATE TYPE project_table AS TABLE OF project_t;
The following example invokes method constructor COL.GETBAR():
CREATE TYPE foo AS OBJECT (a1 NUMBER, MEMBER FUNCTION getbar RETURN NUMBER,); CREATE TABLE footab(col foo); SELECT col.getbar() FROM footab;
Unlike function invocations, method invocations require parentheses, even when the methods do not have additional arguments.
The next example invokes the system-defined constructor to construct the FOO_T object and insert it into the FOO_TAB table:
CREATE TYPE foo_t AS OBJECT (a1 NUMBER, a2 NUMBER); CREATE TABLE foo_tab (b1 NUMBER, b2 foo_t); INSERT INTO foo_tab VALUES (1, foo_t(2,3));
|
See Also:
Oracle8i Application Developer's Guide - Fundamentals and PL/SQL User's Guide and Reference for more information about constructors. |
The following example changes the definition of the EMPLOYEE_T type to associate it with the CONSTRUCT_EMP function:
CREATE OR REPLACE TYPE employee_t AS OBJECT( empid RAW(16), ename CHAR(31), dept REF department_t, STATIC function construct_emp (name VARCHAR2, dept REF department_t) RETURN employee_t );
This statement requires the following type body statement:
CREATE OR REPLACE TYPE BODY employee_t IS STATIC FUNCTION construct_emp (name varchar2, dept REF department_t) RETURN employee_t IS BEGIN return employee_t(SYS_GUID(),name,dept); END; END;
This type and type body definition allows the following operation:
INSERT INTO emptab VALUES (employee_t.construct_emp('John Smith', NULL));
|
|
![]() Copyright © 1999 Oracle Corporation. All Rights Reserved. |
|