User defined functions
This is a translation reference to convert Oracle functions to snowflake.
General Description
Most Oracle UDFs and UDFs inside packages, are being transformed to Snowflake Stored Procedures, to maintain functional equivalence, due to Snowflake UDFs having some limitations executing DML (Data Manipulation Language) statements.
Since functions are being transformed into procedures, the transformation reference for PL/SQL also applies here.
Translation
Create Function
Oracle
--Additional Params: -t JavaScript
CREATE OR REPLACE FUNCTION FUN1(PAR1 VARCHAR)
RETURN VARCHAR
IS
VAR1 VARCHAR(20);
VAR2 VARCHAR(20);
BEGIN
SELECT COL1 INTO VAR1 FROM TABLE1 where col1 = 1;
VAR2 := PAR1 || VAR1;
RETURN VAR2 ;
END;Snowflake
Function inside Package
Oracle
Snowflake
Return data type mapping
Oracle PL SQL type
Snowflake equivalent
NUMBER
FLOAT
LONG
VARCHAR
VARCHAR2
STRING
BLOB
BINARY
BFILE
BINARY
Call
Inside queries
Calls of functions that were transformed to procedures inside queries are converted into a an empty Snowflake JavaScript UDF. This Snowflake UDF is generated in the STUB_UDF.sql file inside the UDF Helpers directory.
Oracle
Snowflake
Inside other functions or stored procedures
Oracle
The functions that are converted to procedures are called using the EXEC Snowflake helper.
Oracle
Snowflake:
Oracle
Snowflake
Different cases and limitations
Functions with DMLs
These functions cannot be executed in queries in Oracle, so their usage wont be limited when transforming them to Snowflake Procedures.
Oracle
Snowflake
Functions with only one SELECT INTO
These functions are transformed to Snowflake SQL functions by removing the INTO part of the select.
Oracle
Snowflake
Functions with only logic
UDFs that do not use any SQL statement are converted into Snowflake JavaScript UDFs.
Oracle
Snowflake
Functions with more than one SQL statement
UDFs transformed into procedures cannot be called from a query.
Oracle
Snowflake
Functions with only logic and built-in SQL functions
Oracle
Current transformation to Snowflake
Transformation planned to be delivered in the future
RETURN CASE
The transformation is the same transformation when the CASE is use to assign a variable. You can check the transformation of CASE in the PL/SQL section.
Oracle
SnowFlake
Related EWIs
SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.
SSC-EWI-0068: User defined function was transformed to a Snowflake procedure.
SSC-EWI-0073: Pending Functional Equivalence Review.
Last updated