LET (Snowflake Scripting) | Snowflake Documentation (original) (raw)
Assigns an expression to a Snowflake Scripting variable, cursor, or RESULTSET.
Syntax¶
LET { | | }
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 { DEFAULT | := } ;
LET { DEFAULT | := } ;
Where:
_variablename_
The name of the variable. The name must follow the naming rules for object identifiers.
_type_
DEFAULT _expression_
or .:= _expression_
Assigns the value of
_expression_
to the variable.If both
_type_
and_expression_
are 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:
- Working with variables
- IF statements
- Working with loops
- Examples for common use cases of Snowflake Scripting
Cursor assignment syntax¶
Use one of the following syntaxes to assign an expression to a cursor.
LET CURSOR FOR ;
LET CURSOR FOR ;
Where:
_cursorname_
The name to give the cursor. This can be any valid Snowflake identifierthat is not already in use in this block. The identifier is used by other cursor-related commands, such as FETCH (Snowflake Scripting).
_query_
The query that defines the result set that the cursor iterates over.
This can be almost any valid SELECT statement.
_resultsetname_
The 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.
:= ( ) ;
Where:
_resultsetname_
The 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 _query_
or .:= _query_
Assigns the value of
_query_
to 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.