How to write SQL function in SQL script

Hi,
I am trying to write a SQL function in SQL script
CREATE OR REPLACE FUNCTION fun1() RETURNS VOID AS
DECLARE
VAR_VALUE INTEGER;
e RECORD;
BEGIN
for e in select col1,col2 from table
Loop
--BODY OF FUNCTION
END LOOP;
END;
I am getting error while running the code in DECLARE section stating unexpected <EOF>.
Can anyone help me to get rid of this issue and help me in executing the SQL Script for SQL function.
Thanks in advance.
Regards,
Deepak
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,420 Neuron
What SQL engine do you use?
-
I am using Snowflake
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,420 Neuron
And it's that how you create a SQL function in Snowflake? (ie the correct syntax):
https://docs.snowflake.com/en/developer-guide/udf/sql/udf-sql-introductionIt looks like you copied the syntax from this documentation page which is showing how to create a function in PL/pgSQL which is PostgreSQL Procedural languange.
Each SQL engine has it's own SQL syntax, it's own SQL procedural language, etc. You can't mix and match.