The SET variable statement produces a result table consisting of at most one row and assigns the values in that row to host variables.
This statement can only be embedded in an application program. It is an executable statement that cannot be dynamically prepared.
If an expression includes a function, the authorization ID of the statement must include at least one of the following for each user-defined function:
The authorization ID of the statement has the EXECUTE privilege on a function when:
If a row-subselect is specified, see Queries for an explanation of the authorization required for each subselect.
.-,---------------------------------------------------------------------------------------.
V |
>>-SET----+-host-variable-- = --+-expression--------------+------------------------------------+--+->
| +-NULL--------------------+ |
| '-(--scalar-subselect--)--' |
| .-,----------------. .-,----------------------------. |
| V | V | |
'-(-----host-variable---+---)---- = --(---+----+-expression--------------+--+-+---)--'
| +-NULL--------------------+ |
| '-(--scalar-subselect--)--' |
'-row-subselect---------------------'
>--------------------------------------------------------------><
|
The value to be assigned to each host-variable can be specified immediately following the host-variable, for example, host-variable = expression, host-variable = expression. Or, sets of parentheses can be used to specify all the host-variables and then all the values, for example, (host-variable, host-variable) = (expression, expression).
The data type of each host variable must be compatible with its corresponding result column. Each assignment is made according to the rules described in Assignments and Comparisons. The number of host-variables specified to the left of the equal operator must equal the number of values in the corresponding result specified to the right of the equal operator. If the value is null, an indicator variable must be provided. If an assignment error occurs, the value is not assigned to the variable, and no more values are assigned to variables. Any values that have already been assigned to variables remain assigned.
If an error occurs as the result of an arithmetic expression in the expression or SELECT list of the subselect (division by zero, or overflow) or a character conversion error occurs, the result is the null value. As in any other case of a null value, an indicator variable must be provided. The value of the host variable is undefined. In this case, however, the indicator variable is set to -2. Processing of the statement continues as if the error had not occurred. (However, this error causes a positive SQLCODE.) If you do not provide an indicator variable, a negative value is returned in the SQLCODE field of the SQLCA. It is possible that some values have already been assigned to host variables and will remain assigned when the error occurs.
If the specified host variable is character and is not large enough to contain the result, 'W' is assigned to SQLWARN1 in the SQLCA. The actual length of the result is returned in the indicator variable associated with the host-variable, if an indicator variable is provided.
If the specified host variable is a C NUL-terminated host variable and is not large enough to contain the result and the NUL-terminator:
Assign the value of the CURRENT PATH special register to host variable HV1.
EXEC SQL SET :HV1 = CURRENT PATH;
Assume that LOB locator LOB1 is associated with a CLOB value. Assign a portion of the CLOB value to host variable DETAILS using the LOB locator.
EXEC SQL SET :DETAILS = SUBSTR(:LOB1,1,35);