Oracle9i SQL Reference
Release 1 (9.0.1)

Part Number A90125-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

SQL Statements:
ALTER TRIGGER to constraint_clause, 3 of 12


ALTER TYPE

Purpose

Use the ALTER TYPE statement to add or drop member attributes or methods. You can change the existing properties (FINAL or INSTANTIABLE) of an object type, and you can modify the scalar attributes of the type.

You can also use this statement to recompile the specification or body of the type or to change the specification of an object type by adding new object member subprogram specifications.

Prerequisites

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.

Syntax

alter_type::=


Text description of statements_428.gif follows
Text description of alter_type

invoker_rights_clause::=


Text description of statements_421.gif follows
Text description of invoker_rights_clause

element_spec::=


Text description of statements_42a.gif follows
Text description of element_spec

inheritance_clauses::=


Text description of statements_43a.gif follows
Text description of inheritance_clauses

subprogram_clauses::=


Text description of statements_44a.gif follows
Text description of subprogram_clauses

procedure_spec::=


Text description of statements_419.gif follows
Text description of procedure_spec

function_spec::=


Text description of statements_420.gif follows
Text description of function_spec

map_order_function_spec::=


Text description of statements_45a.gif follows
Text description of map_order_function_spec

pragma_clause::=


Text description of statements_415.gif follows
Text description of pragma_clause

alter_method_spec::=


Text description of statements_46a.gif follows
Text description of alter_method_spec

alter_attribute_definition::=


Text description of statements_48a.gif follows
Text description of alter_attribute_definition

dependent_handling_clause::=


Text description of statements_49a.gif follows
Text description of dependent_handling_clause

exceptions_clause::=


Text description of statements_410a.gif follows
Text description of exceptions_clause

Keywords and Parameters

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 Clause

Specify COMPILE to compile the object type specification and body. This is the default if neither SPECIFICATION nor BODY is specified.

During recompilation, Oracle drops all persistent compiler switch settings, retrieves them again from the session, and stores them at the end of compilation. To avoid this process, specify the REUSE SETTINGS clause.

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.

DEBUG

Specify DEBUG to instruct the PL/SQL compiler to generate and store the code for use by the PL/SQL debugger.

SPECIFICATION

Specify SPECIFICATION to compile only the object type specification.

BODY

Specify BODY to compile only the object type body.

REUSE SETTINGS

Specify REUSE SETTINGS to prevent Oracle from dropping and reacquiring compiler switch settings. With this clause, Oracle preserves the existing settings and uses them for the recompilation.

If you specify both DEBUG and REUSE SETTINGS, Oracle sets the persistently stored value of the PLSQL_COMPILER_FLAGS parameter to INTERPRETED, DEBUG. No other compiler switch values are changed.

See Also:

PL/SQL User's Guide and Reference and Oracle9i Application Developer's Guide - Fundamentals for more information on the interaction of the PLSQL_COMPILER_FLAGS parameter with the COMPILE clause 

REPLACE AS OBJECT Clause

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.

attribute

Specify an object attribute name. Attributes are data items with a name and a type specifier that form the structure of the object.

element_spec

Specify the elements of the redefined object.

inheritance_clauses

As part of the element_spec, the inheritance_clauses let you specify the relationship between super- and subtypes.

OVERRIDING

Specify OVERRIDING to indicate that this method overrides a method defined in the supertype. This keyword is required if the method redefines a supertype method. NOT OVERRIDING is the default.

Restriction: The OVERRIDING clause is not valid for a SQLJ object type.

FINAL

Specify FINAL to indicate that this method cannot be overridden by any subtype of this type. The default is NOT FINAL.

NOT INSTANTIABLE

Specify NOT INSTANTIABLE if the type does not provide an implementation for this method. By default all methods are INSTANTIABLE.

subprogram_clauses

The MEMBER and STATIC clauses let 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.

See Also:

 
procedure_spec

Enter the specification of a procedure subprogram.

function_spec

Enter the specification of a function subprogram.

pragma_clause

The pragma_clause is a complier directive that denies member functions read/write access to database tables, packaged variables, or both, and thereby helps to avoid side effects.

Oracle Corporation recommends that you avoid using this clause unless you must do so for backward compatibility of your applications. This clause has been deprecated, because beginning with Oracle9i, Oracle runs purity checks at run time.

Restriction: The pragma_clause is not valid when dropping a method.

See Also:

Oracle9i Application Developer's Guide - Fundamentals 

map_order_function_spec

You can declare either a MAP method or an ORDER method, but not both. However, a subtype can override a MAP method if the supertype defines a NOT FINAL MAP method. If you declare either method, you can compare object instances in SQL.

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.

See Also:

"Object Values"for more information about object value comparisons 

A subtype cannot define a new MAP method. However, it can override an inherited MAP method.

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.

AUTHID CURRENT_USER Clause

Specify CURRENT_USER if you want the member functions and procedures of the object type to execute with the privileges of CURRENT_USER. This clause creates an invoker-rights type.

This clause also specifies that external names in queries, DML operations, and dynamic SQL statements resolve in the schema of CURRENT_USER. External names in all other statements resolve in the schema in which the type resides.


Note:

You must specify this clause to maintain invoker-rights status for the type if you created it with this status. Otherwise the status will revert to definer rights. 


AUTHID DEFINER Clause

Specify DEFINER if you want the member functions and procedures of the object type to 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.

See Also:

 

alter_method_spec

The alter_method_spec lets you add a method to or drop a method from type. Oracle disables any function-based indexes that depend on the type.

In one ALTER TYPE statement you can add or drop multiple methods, but you can reference each method only once.

ADD

When you add a method, its name must not conflict with any existing attributes in its type hierarchy.

DROP

When you drop a method, Oracle removes the method from the target type.

Restriction: You cannot drop from a subtype a method inherited from its supertype. Instead you must drop the method from the supertype.

subprogram_clauses

The MEMBER and STATIC clauses let you add a procedure subprogram to or drop it from the object type.

Restriction: You cannot define a STATIC method on a subtype that redefines a MEMBER method in its supertype, or vice versa.

See Also:

the description of the subprogram_clauses in CREATE TYPE 

map_order_function_spec

If you declare either a MAP or ORDER method, you can compare object instances in SQL.

Restriction: You cannot add an ORDER method to a subtype.

See Also:

the description of map_order_function_spec in CREATE TYPE 

alter_attribute_definition

The alter_attribute_definition clause lets you add, drop, or modify an attribute of an object type. In one ALTER TYPE statement, you can add, drop, or modify multiple member attributes or methods, but you can reference each attribute or method only once.

ADD ATTRIBUTE

The name of the new attribute must not conflict with existing attributes or methods in the type hierarchy. Oracle adds the new attribute to the end of the locally defined attribute list.


Note:

If you add the attribute to a supertype, it is inherited by all of its subtypes. In subtypes, inherited attributes always precede declared attributes. Therefore, you may need to update the mappings of the implicitly altered subtypes after adding an attribute to a supertype. 


DROP ATTRIBUTE

When you drop an attribute from a type, Oracle drops the column corresponding to the dropped attribute as well as any indexes, statistics, and constraints referencing the dropped attribute.

You need not specify the datatype of the attribute you are dropping.

Restrictions:

MODIFY ATTRIBUTE

This clause lets you modify the datatype of an existing scalar attribute. For example, you can increase the length of a VARCHAR2 or RAW attribute, or you can increase the precision or scale of a numeric attribute.

Restriction: You cannot expand the size of an attribute referenced in a function-based index, domain index, or cluster key.

[NOT] FINAL

Use the [NOT] FINAL clause to indicate whether any further subtypes can be created for this type:

Restriction: You cannot change a user-defined type from NOT FINAL to FINAL if the type has any subtypes.

[NOT] INSTANTIABLE

Use the [NOT] INSTANTIABLE clause to indicate whether any object instances of this type can be constructed:

Restriction: You cannot change a user-defined type from INSTANTIABLE to NOT INSTANTIABLE if the type has any table dependents.

dependent_handling_clause

The dependent_handling_clause lets you instruct Oracle how to handle objects that are dependent on the modified type. If this clause is not specified, the ALTER TYPE statement will abort if the target type has any dependent type or table.

INVALIDATE Clause

Specify INVALIDATE to invalidate all dependent objects without any checking mechanism.


Note:

Because Oracle does not validate the type change, you should use this clause with caution. For example, if you drop an attribute that is a partitioning or cluster key, you will be unable to write to the table. 


CASCADE Clause

Specify the CASCADE clause if you want to propagate the type change to dependent types and tables. Oracle aborts the statement if any errors are found in the dependent types or tables unless you also specify FORCE.

INCLUDING TABLE DATA

Specify INCLUDING TABLE DATA to convert data stored in all user-defined columns to the most recent version of the column's type. This is the default.


Note:

You must specify this clause if your column data is in Oracle8 release 8.0 image format. This clause is also required if the type property is being changed between FINAL and NOT FINAL 


When you specify INCLUDING TABLE DATA, all of the tablespaces containing the table's data must be in read/write mode.

If you specify NOT INCLUDING TABLE DATA, Oracle upgrades the metadata of the column to reflect the changes to the type, but does not scan the dependent column and update the data as part of this ALTER TYPE statement. However, the dependent column data remains accessible and the results of subsequent queries of the data will reflect the type modifications.

See Also:

Oracle9i Application Developer's Guide - Object-Relational Features for more information on the implications of not including table data when modifying type attribute 

FORCE

Specify FORCE if you want Oracle to ignore the errors from dependent tables and indexes and log all errors in the specified exception table. The exception table must already have been created by executing the DBMS_UTILITY.CREATE_ALTER_TYPE_ERROR_TABLE procedure.

Examples

Adding a Member Function Example

The following example uses the data_typ object type, which was created in "Object Type Examples". A method is added to data_typ and its type body is modified to correspond. The date formats are consistent with the order_date column of the oe.orders demo table:

ALTER TYPE data_typ 
   ADD MEMBER FUNCTION qtr(der_qtr DATE) 
   RETURN CHAR CASCADE;

CREATE OR REPLACE TYPE BODY data_typ IS 
  MEMBER FUNCTION prod (invent NUMBER) RETURN NUMBER IS 
  BEGIN 
  RETURN (year + invent); 
  END; 
     MEMBER FUNCTION qtr(der_qtr DATE) RETURN CHAR IS 
     BEGIN 
       IF (der_qtr < TO_DATE('01-APR', 'DD-MON')) THEN 
         RETURN 'FIRST'; 
       ELSIF (der_qtr < TO_DATE('01-JUL', 'DD-MON')) THEN 
         RETURN 'SECOND'; 
       ELSIF (der_qtr < TO_DATE('01-OCT', 'DD-MON')) THEN 
         RETURN 'THIRD'; 
       ELSE 
         RETURN 'FOURTH'; 
       END IF; 
     END; 
   END;
/
Adding a Collection Attribute Example

The following example adds the phone_list_typ varray from the demo oe schema to the customer_address_typ object column of the customers table:

ALTER TYPE cust_address_typ
   ADD ATTTRIBUTE (phone phone_list_typ) CASCADE;
Recompiling a Type

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;
Recompiling a Type Specification

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 
      BEGIN  
         dbms_output.put_line(c1);
         RETURN c1; 
      END; 
   END; 

In the following example, both the specification and body of link2 are invalidated.

ALTER TYPE link1 ADD ATTRIBUTE (b NUMBER) INVALIDATE;

You must recompile the type by recompiling the specification and body in separate statements:

ALTER TYPE link2 COMPILE SPECIFICATION;
         
ALTER TYPE link2 COMPILE BODY;
         

Alternatively, you can compile both specification and body at the same time:

ALTER TYPE link2 COMPILE;

Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback