Skip Headers
Oracle® Database PL/SQL User's Guide and Reference
10g Release 2 (10.2)

Part Number B14261-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

%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".

Syntax

%type attribute ::=

Description of type_attribute.gif follows
Description of the illustration type_attribute.gif

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.

Usage Notes

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.

Examples

For examples, see the following:


Example 1-15, "Using a PL/SQL Collection Type"
Example 2-6, "Using %TYPE With the Datatype of a Variable"
Example 2-7, "Using %TYPE With Table Columns"
Example 2-15, "Using a Subprogram Name for Name Resolution"
Example 2-10, "Assigning Values to a Record With a %ROWTYPE Declaration"
Example 3-11, "Using SUBTYPE With %TYPE and %ROWTYPE"
Example 5-5, "Declaring a Procedure Parameter as a Nested Table"
Example 5-7, "Specifying Collection Element Types with %TYPE and %ROWTYPE"
Example 5-42, "Declaring and Initializing Record Types"
Example 6-1, "Data Manipulation With PL/SQL"
Example 6-13, "Fetching Bulk Data With a Cursor"
Example 13-1, "Declaring and Assigning Values to Variables"

Related Topics


"Constant and Variable Declaration"
"%ROWTYPE Attribute"