id="assignstmt">assignment-statement

The assignment-statement assigns a value to an SQL parameter or SQL variable.

 

Syntax


Click to skip syntax diagram


Read syntax diagram

Skip visual syntax diagram>>-+--------+--SET--assignment-clause-------------------------->< '-label:-'

assignment-clause:


Read syntax diagram

Skip visual syntax diagram .-,-----------------------------------------------------------------------. V | >>---+-+-SQL-parameter-name-+-- = --+-expression-+-------------------------+-+->< | '-SQL-variable-name--' +-NULL-------+ | | '-DEFAULT----' | | .-,----------------------. .-,--------------. | | V | V | | '-(----+-SQL-parameter-name-+-+--)-- = --+-(----+-expression-+-+--)-+-' '-SQL-variable-name--' | +-NULL-------+ | | '-DEFAULT----' | '-row-fullselect-----------'

 

Description

label

Specifies the label for the assignment-statement statement. The label name cannot be the same as the routine name or another label within the same scope. For more information, see Labels.

SQL-parameter-name

Identifies the SQL parameter that is the assignment target. The SQL parameter must be specified in parameter-declaration in the CREATE PROCEDURE or CREATE FUNCTION statement.

SQL-variable-name

Identifies the SQL variable that is the assignment target. SQL variables can be defined in a compound statement or be a transition variable.

expression or NULL

Specifies the expression or value that is the source for the assignment.

DEFAULT

Specifies that the default value for the column associated with the transition variable will be used. This can only be specified in SQL triggers for transition variables.

row-fullselect

A fullselect that returns a single result row. The result column values are assigned to the corresponding SQL variable or parameter. If the result of the fullselect is no rows, then null values are assigned. An error is returned if there is more than one row in the result.

 

Notes

Assignment rules: Assignments in the assignment statement must conform to the SQL assignment rules as described in Assignments and comparisons. If assigning to a string variable, storage assignment rules apply.

Assignment rules for SQL parameters: An IN parameter can appear on the left or right side of an assignment-statement. When control returns to the caller, the original value of the IN parameter is retained. An OUT parameter can also appear on the left or right side of an assignment-statement. If used without first being assigned a value, the value is null. When control returns to the caller, the last value that is assigned to an OUT parameter is returned to the caller. For an INOUT parameter, the first value of the parameter is determined by the caller, and the last value that is assigned to the parameter is returned to the caller.

Special Registers: If a variable has been declared with an identifier that matches the name of a special register (such as PATH), then the variable must be delimited to distinguish it from assignment to the special register (for example, SET "PATH" = 1; for a variable called PATH declared as an integer).

SQLCODE and SQLSTATE: The SQLCODE and SQLSTATE will be reset and the diagnostic area or SQLCA initialized for each assignment-statement other than assignment-statements that:

 

Example

Increase the SQL variable p_salary by 10 percent.

  SET p_salary = p_salary + (p_salary * .10)

Set SQL variable p_salary to the null value

  SET p_salary = NULL


[ Top of Page | Previous Page | Next Page | Contents |
Index ]