Stored Procedures, UDFs & Snowflake Scripting
Turn a repeated SQL rule into a reusable function, then build a workflow that handles success and failure deliberately.
Before you begin
Intermediate · 8 lessons. Complete Module 04 SQL and transaction foundations. Track 2 file-loading labs are not required for these self-contained samples.
Start with lesson 1 to create M10_LAB inside the learning database from Module 03. Use an authorized role and warehouse; later lessons need function, procedure and table creation privileges. Python and Java handlers are optional extensions; the main lab uses SQL. Commands run only in your own learning environment.
Start Module 10 →From a calculation to a controlled workflow
- Lesson 1 · About 20 min
Choose a function or a procedure
A function calculates a result inside a query. A stored procedure packages a workflow that you invoke with CALL.
Read and practise → - Lesson 2 · About 20 min
Build a reusable SQL transformation
A SQL UDF gives a business calculation a name and a typed input/output contract.
Read and practise → - Lesson 3 · About 20 min
Return rows with a SQL UDTF
A table function returns a table-shaped result. Use TABLE(...) to place it in a query’s FROM clause.
Read and practise → - Lesson 4 · About 20 min
Understand SQL, Python, Java and JavaScript handlers
A handler is the code Snowflake executes when a routine is called. Language choice changes syntax, type mapping, packaging and runtime requirements.
Read and practise → - Lesson 5 · About 20 min
Variables, IF/ELSE and CASE
Snowflake Scripting lets a block remember values and choose which statements to execute.
Read and practise → - Lesson 6 · About 20 min
Loops, cursors and result sets
A loop repeats work; a cursor walks query rows; a RESULTSET points to a query result that can be returned as a table.
Read and practise → - Lesson 7 · About 20 min
Caller rights, owner rights and execution access
Execution rights determine whose privileges a procedure uses. Invoking a routine and accessing its underlying objects are separate permission questions.
Read and practise → - Lesson 8 · About 20 min
Lab: transform a batch and roll back on failure
Combine a reusable calculation with a procedure that owns its transaction, validates inputs and re-raises failures after rollback.
Read and practise →
Your final lab
Apply a discount function to a two-row batch. Confirm a successful commit, then deliberately fail after a delete and explain why rollback preserves the prior result.
Module 11 — Streams + Tasks: CDC & Orchestration continues this learning path.
Continue to Module 11 →Return to curriculum →