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

Assignment Statement

The assignment statement sets the current value of a variable, field, parameter, or element that has been declared in the current scope.

The assignment operator (:=) in the assignment statement can also appear in a constant or variable declaration. In a variable declaration, it assigns a default value to the variable. Without a default value, a variable is initialized to NULL every time a block is entered.

If a variable does not have a default value, always use the assignment statement to assign a value to it before using it in an expression.

Syntax

assignment_statement ::=

assignment_statement
Description of the illustration assignment_statement.gif

(expression ::=)

Keyword and Parameter Descriptions

attribute_name

The name of an attribute of object_type. The name must be unique within object_type (but can be used in other object types).

You cannot initialize an attribute in its declaration. You cannot impose the NOT NULL constraint on an attribute.

See Also:

CREATE TYPE Statement for information about attributes of object types

collection_name

The name of a collection.

cursor_variable_name

The name of a PL/SQL cursor variable.

expression

The expression whose value is to be assigned to the target (the item to the left of the assignment operator) when the assignment statement executes.

The value of expression must have a data type that is compatible with the data type of the target.

If the target is a variable defined as NOT NULL, the value of expression cannot be NULL. If the target is a Boolean variable, the value of expression must be TRUE, FALSE, or NULL. If the target is a cursor variable, the value of expression must also be a cursor variable.

field_name

The name of a field in record_name.

Specify field_name if you want to assign the value of expression to a specific field of a record.

Omit field_name if you want to assign the value of expression to all fields of record_name at once; that is, if you want to assign one record to another. You can assign one record to another only if their declarations refer to the same table or cursor, as in Example 2-17, "Assigning One Record to Another, Correctly and Incorrectly".

host_cursor_variable_name

The name of a cursor variable declared in a PL/SQL host environment and passed to PL/SQL as a bind argument.

The data type of a host cursor variable is compatible with the return type of any PL/SQL cursor variable.

host_variable_name

The name of a variable declared in a PL/SQL host environment and passed to PL/SQL as a bind argument.

index

A numeric expression whose value has data type PLS_INTEGER or a data type implicitly convertible to PLS_INTEGER (see Table 3-10, "Possible Implicit PL/SQL Data Type Conversions").

Specify index if you want to assign the value of expression to a specific element of collection_name.

Omit index if you want to assign the value of expression to all elements of collection_name at once; that is, if you want to assign one collection to another. You can assign one collection to another only if the collections have the same data type (not merely the same element type).

indicator_name

The name of an indicator variable for host_variable_name.

An indicator variable indicates the value or condition of its host variable. For example, in the Oracle Precompiler environment, indicator variables let you detect NULL or truncated values in output host variables.

object_name

The name of an instance of an object type.

parameter_name

The name of a formal OUT or IN OUT parameter of the subprogram in which the assignment statement appears.

record_name

The name of a user-defined or %ROWTYPE record.

variable_name

The name of a PL/SQL variable.

Examples

Related Topics