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".
%type attribute ::=
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.
variable_name
A variable, previously declared in the same scope.
The %TYPE
attribute is particularly useful when declaring variables, fields, and parameters that refer to database columns. Your code can keep working even when the lengths or types of the columns change.
For examples, see the following: