BEGIN … END (Snowflake Scripting)¶
BEGIN and END define a Snowflake Scripting block.
For more information on blocks, see Understanding blocks in Snowflake Scripting.
Syntax¶
Where:
statementA statement can be any of the following:
exception_handlerSpecifies how exceptions should be handled. Refer to Handling exceptions and EXCEPTION (Snowflake Scripting).
Usage notes¶
The keyword
ENDmust be followed immediately by a semicolon, or followed immediately by a label that is immediately followed by a semicolon.The keyword
BEGINmust not be followed immediately by a semicolon.BEGINandENDare usually used inside another language construct, such as a looping or branching construct, or inside a stored procedure. However, this is not required. A BEGIN/END block can be the top-level construct inside an anonymous block.Blocks can be nested.
Examples¶
This is a simple example of using BEGIN and END to group related statements. This example creates two
related tables.
The next example is similar; the statements are grouped into a block and are also inside a transaction within that block:
In this example, the statements are inside a branching construct.