A Named Constant Can Be Assigned a Value Using a Set Statement.
Consignment Statement
An assignment statement sets the current value of a variable, field, parameter, or chemical element. The argument consists of an assignment target followed by the consignment operator and an expression. When the statement is executed, the expression is evaluated and the resulting value is stored in the target. For more information, run across "Assigning Values to Variables".
Syntax
assignment statement ::=
Description of the illustration assignment_statement.gif
Keyword and Parameter Description
attribute_name
An attribute of an object type. The name must be unique inside the object blazon (but tin be reused in other object types). You lot cannot initialize an attribute in its declaration using the assignment operator or DEFAULT
clause. As well, you lot cannot impose the Not
Cypher
constraint on an aspect.
collection_name
A nested table, index-by tabular array, or varray previously declared within the current telescopic.
cursor_variable_name
A PL/SQL cursor variable previously declared inside the current scope. Only the value of some other cursor variable tin can exist assigned to a cursor variable.
expression
A combination of variables, constants, literals, operators, and function calls. The simplest expression consists of a unmarried variable. For the syntax of expression
, see "Expression Definition". When the assignment statement is executed, the expression is evaluated and the resulting value is stored in the assignment target. The value and target must accept compatible datatypes.
field_name
A field in a user-defined or %ROWTYPE
record.
host_cursor_variable_name
A cursor variable alleged in a PL/SQL host environment and passed to PL/SQL every bit a bind variable. The datatype of the host cursor variable is compatible with the return blazon of any PL/SQL cursor variable. Host variables must be prefixed with a colon.
host_variable_name
A variable alleged in a PL/SQL host environment and passed to PL/SQL as a bind variable. Host variables must exist prefixed with a colon.
index
A numeric expression that must return a value of blazon PLS_INTEGER
, BINARY_INTEGER
, or a value implicitly convertible to that datatype.
indicator_name
An indicator variable declared in a PL/SQL host environment and passed to PL/SQL. Indicator variables must be prefixed with a colon. An indicator variable indicates the value or condition of its associated host variable. For example, in the Oracle Precompiler surroundings, indicator variables permit yous notice nulls or truncated values in output host variables.
object_name
An instance of an object type previously declared within the current scope.
parameter_name
A formal OUT
or IN
OUT
parameter of the subprogram in which the assignment statement appears.
record_name
A user-defined or %ROWTYPE
tape previously declared within the electric current scope.
variable_name
A PL/SQL variable previously declared within the current scope.
Usage Notes
Past default, unless a variable is initialized in its announcement, it is initialized to Zero
every time a block or subprogram is entered. Ever assign a value to a variable before using that variable in an expression.
You cannot assign nulls to a variable defined as NOT
Aught
. If yous endeavour, PL/SQL raises the predefined exception VALUE_ERROR
. Only the values Truthful
, FALSE
, and Naught
tin can be assigned to a Boolean variable. You can assign the effect of a comparison or other test to a Boolean variable.
You can assign the value of an expression to a specific field in a record. You can assign values to all fields in a record at in one case. PL/SQL allows aggregate assignment between entire records if their declarations refer to the same cursor or table. Instance i-2, "Assigning Values to Variables With the Assignment Operator" shows how to copy values from all the fields of one tape to some other:
Y'all can assign the value of an expression to a specific chemical element in a collection, past subscripting the drove proper name.
Examples
Example xiii-1 illustrates diverse ways to declare so assign values to variables.
Example 13-1 Declaring and Assigning Values to Variables
DECLARE wages NUMBER; hours_worked NUMBER := xl; hourly_salary Constant NUMBER := 17.50; -- constant value does not alter country VARCHAR2(64) := 'UNKNOWN'; unknown BOOLEAN; Type comm_tab IS Tabular array OF NUMBER INDEX BY PLS_INTEGER; commissions comm_tab; TYPE jobs_var IS VARRAY(ten) OF employees.job_id%Blazon; jobids jobs_var; CURSOR c1 IS SELECT department_id FROM departments; -- cursor declaration deptid departments.department_id%TYPE; emp_rec employees%ROWTYPE; -- exercise non need Type annunciation in this example Begin /* the following are examples of assignment statements */ wages := hours_worked * hourly_salary; -- compute wages country := UPPER('italian republic'); unknown := (state = 'UNKNOWN'); commissions(5) := 20000 * 0.15; commissions(8) := 20000 * 0.xviii; jobids := jobs_var('ST_CLERK'); jobids.EXTEND(1); jobids(2) := 'SH_CLERK'; OPEN c1; FETCH c1 INTO deptid; Close c1; emp_rec.department_id := deptid; emp_rec.job_id := jobids(2); End; /
For examples, meet the following:
Instance 1-2, "Assigning Values to Variables With the Assignment Operator"
Instance 1-3, "Assigning Values to Variables by SELECTing INTO"
Example one-4, "Assigning Values to Variables as Parameters of a Subprogram"
Example ii-10, "Assigning Values to a Record With a %ROWTYPE Declaration"
Related Topics
"Assigning Values to Variables"
"Constant and Variable Declaration"
"Expression Definition"
"SELECT INTO Statement"
Source: https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/assignment_statement.htm
0 Response to "A Named Constant Can Be Assigned a Value Using a Set Statement."
Post a Comment