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.
Keyword and Parameter Descriptions
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 typesThe name of a collection.
The name of a PL/SQL cursor variable.
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.
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".
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.
The name of a variable declared in a PL/SQL host environment and passed to PL/SQL as a bind argument.
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).
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.
The name of an instance of an object type.
The name of a formal OUT
or IN
OUT
parameter of the subprogram in which the assignment statement appears.
The name of a user-defined or %ROWTYPE
record.
The name of a PL/SQL variable.