Snowflake scripting is procedural extension to SQL with Design features of programming languages.
You can use snowflake scripting for Data Manipulation and Query statement of SQL with procedural unit of code.
Benefit of Snowflake Scripting
Enhanced Data Transformation
Automation of Workflows
Procedural Logic
Integration with SQL
Scalability and Performance
Error Handling and Logging
-------------------------------------------
-- A simple block only requires the keywords BEGIN and END
begin
return 'my first anonyms block' ;
end;
begin
return 'this the first line' ;
return 'this is the second line';
end;
begin
return 'this the first line,' || ' this is the second line' ;
-- return 'this is the second line';
end;
declare
returns string;
begin
return 'hello world';
end;
BEGIN
CREATE or replace TABLE employee (id INTEGER);
CREATE or replace TABLE dependents (id INTEGER);
return 'Table created!';
END;
select * from employee;
declare
returns string;
v number;
begin
v:=1111;
return 'Variable number is ' || :v;
end;
DECLARE
radius_of_circle FLOAT;
area_of_circle FLOAT;
BEGIN
radius_of_circle := 3;
area_of_circle := pi() * radius_of_circle * radius_of_circle;
RETURN area_of_circle;
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();
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;
$$
;
EXECUTE IMMEDIATE $$
DECLARE
radius_of_circle FLOAT;
area_of_circle FLOAT;
BEGIN
radius_of_circle := 3;
area_of_circle := PI() * radius_of_circle * radius_of_circle;
RETURN area_of_circle;
END;
$$
;
EXECUTE IMMEDIATE $$
BEGIN
CREATE OR REPLACE TABLE parent (ID INTEGER);
CREATE OR REPLACE TABLE child (ID INTEGER, parent_ID INTEGER);
RETURN 'Completed';
END;
$$
;
Watch video Introduction to Snowflake Scripting: Basics of Begin and End Blocks online without registration, duration hours minute second in high quality. This video was added by user Data World Solution 18 July 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 11 once and liked it people.