Skip Headers
Oracle® Database PL/SQL Language Reference
11g Release 1 (11.1)

B28370-05
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

Variable

A variable holds a value that can change.

A variable declaration specifies its name, data type, and value, and allocates storage for it. The declaration can also assign an initial value and impose the NOT NULL constraint.

Syntax

variable_declaration ::=

variable_declaration
Description of the illustration variable_declaration.gif

(expression ::=)

datatype ::=

datatype
Description of the illustration datatype.gif

Keyword and Parameter Descriptions

collection_name

A collection (associative array, nested table, or varray) previously declared within the current scope.

collection_type_name

A user-defined collection type defined using the data type specifier TABLE or VARRAY.

cursor_name

An explicit cursor previously declared within the current scope.

cursor_variable_name

A PL/SQL cursor variable previously declared within the current scope.

db_table_name

A database table or view that must be accessible when the declaration is elaborated.

db_table_name.column_name

A database table and column that must be accessible when the declaration is elaborated.

expression

The value to be assigned to the variable when the declaration is elaborated. The value of expression must be of a data type that is compatible with the data type of the variable.

NOT NULL

A constraint that prevents the program from assigning a null value to the variable. Assigning a null to a variable defined as NOT NULL raises the predefined exception VALUE_ERROR.

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.

record_type_name

A user-defined record type that is defined using the data type specifier RECORD.

ref_cursor_type_name

A user-defined cursor variable type, defined using the data type specifier REF CURSOR.

%ROWTYPE

Represents a record that can hold a row from a database table or a cursor. Fields in the record have the same names and data types as columns in the row.

scalar_datatype_name

A predefined scalar data type such as BOOLEAN, NUMBER, or VARCHAR2. Includes any qualifiers for size, precision, and character or byte semantics.

%TYPE

Represents the data type of a previously declared collection, cursor variable, field, object, record, database column, or variable.

variable_name

The name of the variable. For naming conventions, see Identifiers.

Usage Notes

Variables are initialized every time a block or subprogram is entered. By default, variables are initialized to NULL. Whether public or private, variables declared in a package specification are initialized only once for each session.

An initialization clause is required when declaring NOT NULL variables. If you use %ROWTYPE to declare a variable, initialization is not allowed.

Examples

Related Topics