Snowflake Scripting Developer GuideΒΆ

Topics in this section explain how to write a stored procedure in SQL by using Snowflake Scripting. Snowflake Scripting is an extension to Snowflake SQL that adds support for procedural logic. You can use Snowflake Scripting to write stored procedures and procedural code outside of a stored procedure. This guide explains how to use Snowflake Scripting.

Understanding blocks in Snowflake Scripting

Learn the basic structure of Snowflake Scripting code.

Working with variables

Declare and use variables.

Returning a value

Return values from stored procedures and an anonymous block.

Working with conditional logic

Control flow with IF and CASE statements.

Working with loops

Control flow with FOR, WHILE, REPEAT, and LOOP.

Working with cursors

Iterate through query results with a cursor.

Working with RESULTSETs

Iterate over the result set returned by a query.

Handling exceptions

Handle errors by handling and raising exceptions.

Determining the number of rows affected by DML commands

Use global variables to determine the effect of data manipulation language (DML) commands.

Getting the query ID of the last query

Use the global variable SQLID to get the query ID of the last query.

Examples for common use cases

Explore examples of Snowflake Scripting code for some common use cases.

Using Snowflake Scripting in SnowSQL and the Classic Console

Run the Snowflake Scripting examples in SnowSQL and the Classic Console.