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:

DECLARE

Syntax

LET { <variable_assignment> | <cursor_assignment> | <resultset_assignment> }
Copy

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> ;
Copy

Where:

variable_name

The name of the variable. The name must follow the naming rules for Object Identifiers.

type

A SQL data 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:

EXECUTE IMMEDIATE 
$$
DECLARE
  profit number(38, 2) DEFAULT 0.0;
BEGIN
  LET cost number(38, 2) := 100.0;
  LET revenue number(38, 2) DEFAULT 110.0;

  profit := revenue - cost;
  RETURN profit;
END;
$$
;
Copy

Cursor assignment syntax

Use one of the following syntaxes to assign an expression to a cursor.

LET <cursor_name> CURSOR FOR <query> ;
Copy
LET <cursor_name> CURSOR FOR <resultset_name> ;
Copy

Where:

cursor_name

The 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).

query

The query that defines the result set that the cursor iterates over.

This can be almost any valid SELECT statement.

resultset_name

The name of the RESULTSET for the cursor to operate on.

RESULTSET assignment syntax

Use the following syntax to assign an expression to a RESULTSET.

<resultset_name> := ( <query> ) ;
Copy

Where:

resultset_name

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.