Download Oracle Database PL/SQL User's Guide and Reference

Transcript
%TYPE Attribute
%TYPE Attribute
The %TYPE attribute lets use the datatype of a field, record, nested table, database
column, or variable in your own declarations, rather than hardcoding the type names.
You can use the %TYPE attribute as a datatype specifier when declaring constants,
variables, fields, and parameters. If the types that you reference change, your
declarations are automatically updated. This technique saves you from making code
changes when, for example, the length of a VARCHAR2 column is increased. Note that
column constraints, such as the NOT NULL and check constraint, or default values are
not inherited by items declared using %TYPE. For more information, see "Using the
%TYPE Attribute" on page 2-10.
Syntax
%type attribute ::=
collection_name
cursor_variable_name
object name
.
field_name
%
TYPE
record_name
db_table_name
.
column_name
variable_name
Keyword and Parameter Description
collection_name
A nested table, index-by table, or varray previously declared within the current scope.
cursor_variable_name
A PL/SQL cursor variable previously declared within the current scope. Only the
value of another cursor variable can be assigned to a cursor variable.
db_table_name.column_name
A table and column that must be accessible when the declaration is elaborated.
object_name
An instance of an object type, previously declared within the current scope.
record_name
A user-defined or %ROWTYPE record, previously declared within the current scope.
record_name.field_name
A field in a user-defined or %ROWTYPE record, previously declared within the current
scope.
PL/SQL Language Elements 13-119