4.Understanding Blocks in Snowflake Scripting| How to write procedural code in a block| Snowflake
In this video, I am going to explain how to write procedural code in a block. In Snowflake Scripting, you write procedural code within a Snowflake Scripting block. Understanding the Structure of a Block Using a Block in a Stored Procedure Using an Anonymous Block --A block has the following basic structure: DECLARE ... (variable declarations, cursor declarations, RESULTSETS, Exceptions.) ... --This section of the block is optional. BEGIN ... (Snowflake Scripting and SQL statements) ... EXCEPTION ... (statements for handling exceptions) ... --This section of the block is optional. END; ---A simple block just requires the keywords BEGIN and END. BEGIN -- execution block/mandatory block null; END; BEGIN -- execution block/mandatory block END; --A simple block just requires the keywords BEGIN and END. BEGIN -- execution block/mandatory block return 'A simple block just requires the keywords BEGIN and END.'; END; --- transaction management BEGIN begin ; commit; END; BEGIN begin transaction; commit; END; BEGIN begin transaction; rollback; END; BEGIN begin transaction; rollback; END; DECLARE a number ; BEGIN a := 10; return a; EXCEPTION when other then return object_construct('Error type', 'Other error', 'SQLODE', sqlcode, 'SQLERRM', sqlerrm, 'SQLSTATE', sqlstate); END; DECLARE a number ; BEGIN a := 10; return a/0; EXCEPTION when other then return object_construct('Error type', 'Other error', 'SQLODE', sqlcode, 'SQLERRM', sqlerrm, 'SQLSTATE', sqlstate); END; DECLARE a number ; BEGIN a := 10; return a/0; END; --Using a Block in a Stored Procedure create or replace procedure area() returns float language sql as declare radius float; area_of_circle float; begin radius := 3; area_of_circle := pi() * radius * radius; return area_of_circle; end; call area(); --Using an Anonymous Block begin create table parent (id integer); create table child (id integer, parent_id integer); return 'Completed'; end; desc table parent; desc table child; #snowflakescripting#snowflake#vcklytech#snowflakestoredprocedures
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.