Oracle8i SQL Reference Release 3 (8.1.7) Part Number A85397-01 |
|
SQL Statements:
ALTER TABLE to constraint_clause, 5 of 14
Use the ALTER
TYPE
statement to recompile the specification and/or body, or to change the specification of an object type by adding new object member subprogram specifications.
You cannot change the existing properties (attributes, member subprograms, map or order functions) of an object type, but you can add new member subprogram specifications.
The object type must be in your own schema and you must have CREATE
TYPE
or CREATE
ANY
TYPE
system privilege, or you must have ALTER
ANY
TYPE
system privileges.
schema
Specify the schema that contains the type. If you omit schema
, Oracle assumes the type is in your current schema.
type
Specify the name of an object type, a nested table type, or a rowid type.
COMPILE
Specify COMPILE
to compile the object type specification and body. This is the default if neither SPECIFICATION
nor BODY
is specified.
If recompiling the type results in compilation errors, then Oracle returns an error and the type remains invalid. You can see the associated compiler error messages with the SQL*Plus command SHOW
ERRORS
.
REPLACE
AS
OBJECT
The REPLACE
AS
OBJECT
clause lets you add new member subprogram specifications. This clause is valid only for object types, not for nested table or varray types.
element_list
Specify the elements of the object.
|
Specify an object attribute name. Attributes are data items with a name and a type specifier that form the structure of the object. |
|
|
This clause lets you specify a function or procedure subprogram associated with the object type which is referenced as an attribute. You must specify a corresponding method body in the object type body for each procedure or function specification.
|
|
|
|
Enter the specification of a procedure subprogram. |
|
|
Enter the specification of a function subprogram. |
|
The |
|
|
|
Specify the name of the |
|
|
Specify |
|
|
Specify |
|
|
Specify |
|
|
Specify |
|
|
Specify |
|
|
Specify |
|
You can declare either a If you do not declare either method, you can compare object instances only for equality or inequality. Instances of the same type definition are equal only if each pair of their corresponding attributes is equal. No comparison method needs to be specified to determine the equality of two object types.
|
|
|
|
Specify a member function ( |
|
|
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 |
|
|
|
|
|
Specify 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 |
invoker_rights_clause
The invoker_rights_clause
lets you specify 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 CURRENT_USER
. This specification applies to the corresponding type body as well.
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:
|
In the following example, member function qtr
is added to the type definition of data_t
.
CREATE TYPE data_t AS OBJECT ( year NUMBER, MEMBER FUNCTION prod(invent NUMBER) RETURN NUMBER ); CREATE TYPE BODY data_t IS MEMBER FUNCTION prod (invent NUMBER) RETURN NUMBER IS BEGIN RETURN (year + invent); END; END; ALTER TYPE data_t REPLACE AS OBJECT ( year NUMBER, MEMBER FUNCTION prod(invent NUMBER) RETURN NUMBER, MEMBER FUNCTION qtr(der_qtr DATE) RETURN CHAR ); CREATE OR REPLACE TYPE BODY data_t IS MEMBER FUNCTION prod (invent NUMBER) RETURN NUMBER IS MEMBER FUNCTION qtr(der_qtr DATE) RETURN CHAR IS BEGIN RETURN (year + invent); END; BEGIN RETURN 'FIRST'; END; END;
The following example creates and then recompiles type loan_t
:
CREATE TYPE loan_t AS OBJECT ( loan_num NUMBER, interest_rate FLOAT, amount FLOAT, start_date DATE, end_date DATE ); ALTER TYPE loan_t COMPILE;
The following example compiles the type body of link2
.
CREATE TYPE link1 AS OBJECT (a NUMBER); CREATE TYPE link2 AS OBJECT (a NUMBER, b link1, MEMBER FUNCTION p(c1 NUMBER) RETURN NUMBER); CREATE TYPE BODY link2 AS MEMBER FUNCTION p(c1 NUMBER) RETURN NUMBER IS t13 link1; BEGIN t13 := link1(13); dbms_output.put_line(t13.a); RETURN 5; END; END; CREATE TYPE link3 AS OBJECT (a link2); CREATE TYPE link4 AS OBJECT (a link3); CREATE TYPE link5 AS OBJECT (a link4); ALTER TYPE link2 COMPILE BODY;
The following example compiles the type specification of link2
.
CREATE TYPE link1 AS OBJECT (a NUMBER); CREATE TYPE link2 AS OBJECT (a NUMBER, b link1, MEMBER FUNCTION p(c1 NUMBER) RETURN NUMBER); CREATE TYPE BODY link2 AS MEMBER FUNCTION p(c1 NUMBER) RETURN NUMBER IS t14 link1; BEGIN t14 := link1(14); dbms_output.put_line(t14.a); RETURN 5; END; END; CREATE TYPE link3 AS OBJECT (a link2); CREATE TYPE link4 AS OBJECT (a link3); CREATE TYPE link5 AS OBJECT (a link4); ALTER TYPE link2 COMPILE SPECIFICATION;
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|