LET (Snowflake Scripting)¶
Assigns an expression to a Snowflake Scripting variable, cursor, or RESULTSET.
For more information on variables, cursors, and RESULTSETs, see:
Note
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
- See also:
Syntax¶
LET { <variable_assignment> | <cursor_assignment> | <resultset_assignment> }
The syntax for each type of assignment is described below in more detail.
Variable assignment syntax¶
Use the following syntax to assign an expression to a variable.
LET <variable_name> <type> { DEFAULT | := } <expression> ;
LET <variable_name> { DEFAULT | := } <expression> ;
Where:
variable_nameThe name of the variable. The name must follow the naming rules for object identifiers.
typeDEFAULT expressionor .:= expressionAssigns the value of
expressionto the variable.If both
typeandexpressionare specified, the expression must evaluate to a data type that matches.
For example, the following LET statements declare three variables of type NUMBER,
with precision set to 38 and scale set to 2. All three variables have a default value, using either DEFAULT
or := to specify it.
BEGIN
...
LET profit NUMBER(38, 2) DEFAULT 0.0;
LET revenue NUMBER(38, 2) DEFAULT 110.0;
LET cost NUMBER(38, 2) := 100.0;
...
For more examples, see:
Cursor assignment syntax¶
Use one of the following syntaxes to assign an expression to a cursor.
LET <cursor_name> CURSOR FOR <query> ;
LET <cursor_name> CURSOR FOR <resultset_name> ;
Where:
cursor_nameThe name to give the cursor. This can be any valid Snowflake identifier that is not already in use in this block. The identifier is used by other cursor-related commands, such as FETCH (Snowflake Scripting).
queryThe query that defines the result set that the cursor iterates over.
This can be almost any valid SELECT statement.
resultset_nameThe name of the RESULTSET for the cursor to operate on.
For example, the following LET statement declares cursor c1 for a query:
BEGIN
...
LET c1 CURSOR FOR SELECT price FROM invoices;
...
For more examples, see Working with cursors.
RESULTSET assignment syntax¶
Use the following syntax to assign an expression to a RESULTSET.
<resultset_name> := ( <query> ) ;
Where:
resultset_nameThe name to give the RESULTSET.
The name should be unique within the current scope.
The name must follow the naming rules for Object identifiers.
DEFAULT queryor .:= queryAssigns the value of
queryto the RESULTSET.
For example, the following LET statement declares RESULTSET res for a query:
BEGIN
...
LET res RESULTSET := (SELECT price FROM invoices);
...
For more examples, see Working with RESULTSETs.