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

Some parts in the output code are omitted for clarity reasons.

Create Function

Oracle

IN -> Oracle_01.sql
--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.

When SQL built-in functions are included in the logic the user defined function is converted to a Snowflake procedure. Translation for built in functions to a JavaScript equivalent is planned to be delivered in the future.

Examples for built-in functions: UPPER(), TRIM(), ABS().

Oracle

Snowflake

Functions with more than one SQL statement

Oracle

Snowflake

Functions with only logic and built-in SQL functions

This transformation is planned to be delivery in the future, currently all functions are being transformed to stored procedures.

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

  1. SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.

  2. SSC-EWI-0068: User defined function was transformed to a Snowflake procedure.

  3. SSC-EWI-0073: Pending Functional Equivalence Review.

Last updated