LET

Use the LET statement to assign values to variables or to call a user-defined SPL routine and assign the returned value or values to SPL variables.

Syntax

(1)
Notes:

Element Description Restrictions Syntax
function SPL function to be invoked Must exist in the database Identifier
SPL_var SPL variable to receive a value that the function, expression, or query returns Must be defined and in scope within the statement block Identifier;

Usage

The LET statement can assign a value returned by an expression, function, or query to an SPL variable. At runtime, the value to be assigned is calculated first. The resulting value is cast to the data type of SPL_var, if possible, and the assignment occurs. If conversion is not possible, an error occurs, and the value of the variable remains undefined. (A LET operation that assigns a single value to a single SPL variable is called a simple assignment.)

A compound assignment assigns multiple expressions to multiple SPL variables. The data types of expressions in the expression list do not need to match the data types of the corresponding variables in the variable list, because the database server automatically converts the data types. (For a detailed discussion of casting, see the HCL OneDB™ Guide to SQL: Reference.)

In multiple-assignment operations, the number of variables to the left of the equal ( = ) sign must match the number of values returned by the functions, expressions, and queries listed on the right of the equal ( = ) sign. The following example shows several LET statements that assign values to SPL variables:
LET a   = c + d ;
LET a,b = c,d ;
LET expire_dt = end_dt + 7 UNITS DAY; 
LET name = 'Brunhilda';
LET sname = DBSERVERNAME;
LET this_day = TODAY;
You cannot use multiple values to the right of the equal ( = ) sign to operate on other values. For example, the following statement is not valid:
LET a,b = (c,d) + (10,15); -- INVALID EXPRESSION