SnowConvert AI - Oracle - PL/SQL to Javascript¶
This is a translation reference to convert PL/SQL statements to snowflake JavaScript
Collections & Records¶
Note
Some parts in the output code are omitted for clarity reasons.
Records¶
Note
You might also be interested in Records declaration.
Oracle¶
Snowflake¶
Warning
Transformation for “SELECT INTO Record” is in progress.
Known Issues¶
No issues were found.
Conditional Compilation¶
Description¶
Provides conditional compilation based on the truth value of a condition.
For more information regarding Oracle Conditional Compilation IF, check here.
Sample Source Patterns¶
Possible IF variations¶
Oracle¶
Snowflake Scripting¶
Known issues¶
Transformation of Conditional Compilation is not currently supported.
Related EWIs¶
SSC-EWI-0073: Pending Functional Equivalence Review.
Control Statements¶
Note
Some parts in the output code are omitted for clarity reasons.
IF, ELSIF and ELSE Statement¶
Oracle¶
Snowflake¶
Loop¶
Oracle¶
Snowflake¶
While Statement¶
Oracle¶
Snowflake¶
Related EWIs¶
SSC-EWI-0053: Object may not work.
Declarations¶
Note
Some parts in the output code are omitted for clarity reasons.
Variable declaration and assignment¶
Oracle¶
Snowflake¶
Record variable declaration¶
Note
You might also be interested in Records transformation section.
Oracle¶
Snowflake¶
Rowtype Record variable declaration¶
Oracle¶
Snowflake¶
Constant Declaration¶
Oracle¶
Snowflake¶
Cursor declarations and definition¶
Oracle¶
Note
You might also be interested in Cursor helper
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.
SSC-EWI-0026: The variable may require a cast to date, time or timestamp.
Expressions and operators¶
Expressions¶
Concatenation Operator¶
Note
You might also be interested in Concat helper.
Oracle concatenation is achieved in JavaScript using Template literal. Also it uses the Concat Helper to properly handle concatenations with nulls.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Logical Operators¶
Oracle¶
Snowflake¶
Note
You might also be interested in IS NULL helper.
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Comparison Operator¶
Documentation in progress.
IS [NOT] NULL¶
Note
You might also be interested in IS NULL helper.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Like Operator¶
Note
You might also be interested in Like operator helper.
When there is a LIKE operation, the helper function will be called instead.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Between Operator¶
Note
You may also be interested in Between operator helper.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
IN Operator¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Boolean Expressions¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Function Expressions¶
For Function Expressions inside procedures, they are being converted to the corresponding function or expression in Snowflake. These function calls are passed to an EXEC with a CALL or a SELECT depending on the converted value.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
For more information on the function’s transformations check here.
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
SSC-EWI-OR0013: NLS parameter is not supported.
SSC-FDM-OR0042: Date Type Transformed To Timestamp Has A Different Behavior.
User defined functions¶
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.
Translation¶
Note
Some parts in the output code are omitted for clarity reasons.
Create Function¶
Oracle¶
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 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¶
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.
Note
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¶
Warning
UDFs transformed into procedures cannot be called from a query.
Oracle¶
Snowflake¶
Functions with only logic and built-in SQL functions¶
Note
This transformation is planned to be delivered in the future, currently all functions are being transformed to stored procedures.
Oracle¶
Snowflake¶
RETURN CASE¶
The transformation is the same transformation when the CASE is use to assign a variable.
Oracle¶
Snowflake¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.
SSC-EWI-0073: Pending Functional Equivalence Review.
SSC-FDM-0029: User defined function was transformed to a Snowflake procedure.
Packages¶
Note
Some parts in the output code are omitted for clarity reasons.
Package Declaration¶
This section shows the equivalence between Oracle Package Declaration members and Snowflake statements.
Package Translation options¶
There are two options to migrate packages, each option will affect directly the naming of the objects inside the package. Check here how you can change this mode in the UI.
Let’s suppose that we have the next scenario in Oracle:
A package named
MY_PACKAGE.A procedure inside the package named
MY_PROCEDURE.
Option 1 (Using new schema)¶
With this option, packages are transformed into new schemas. Package elements like functions and procedures are created inside the new schema. If the package is already inside a schema, the name of the package will be joined with the name of the schema with an underscore.
This is the default option for translating packages.
Result:
A schema will be created with the name
MY_PACKAGE.Qualified name of the procedure will be updated to
MY_PACKAGE.MY_PROCEDURE.If the package is inside a schema then the procedure will be updated to
MY_SCHEMA_MY_PACKAGE.MY_PROCEDURE.
Option 2¶
With this option, the name of the package elements will be joined with the package name with an underscore. New schemas will not be created.
Result:
Name of the procedure will be updated to
MY_PACKAGE_MY_PROCEDURE.If the package is inside a schema then the procedure will be updated to
MY_SCHEMA.MY_PACKAGE_MY_PROCEDURE.
Create Package¶
The CREATE PACKAGE statement will be converted to a CREATE SCHEMA statement. Any member inside the package will be converted outside of the package.
Oracle¶
Transformation with option 1 (Using new schema)¶
Transformation with option 2¶
With this option, the Schema won’t be generated and only the inner elements will be kept but with their names renamed.
Procedure and function declaration¶
Procedure and function declarations are not necessary for the transformation to Snowflake. Existing procedure or function declarations will be commented out.
Oracle¶
Transformation with option 1 (Using new schema)¶
Note
Note that that for option 1, the PROCEDURE definition in the package is removed since it is not required by Snowflake.
Variables declaration¶
Note
You might also be interested in variables helper.
Oracle package variables are transformed into Snowflake Session Variables. A prefix is added to the values to know what type it is inside stored procedures. If the value should be null, a “~” is added. Because of this, variables that depend on other variables will require a SUBSTR and a CAST.
Data type and Code mappings¶
Data type or value |
Code |
|---|---|
Numeric types |
# |
Datetime types |
& |
String types |
$ |
NULL values |
~ |
The transformation of the variables will be always the same regardless of the transformation option.
Oracle¶
Snowflake¶
Constants declaration¶
Constants declaration will be declared inside the procedure or functions that use them. Existing package constants declaration will be commented out and a warning will be added.
Oracle¶
Transformation with option 1
Note
Note that the PROCEDURE definition in the package is removed since it is not required by Snowflake.
Other Package members¶
The transformation for other package members like cursors, exceptions and user defined types, is still a work in progress.
Oracle¶
Transformation with option 1¶
Package Body Definition¶
This section shows the equivalence between Oracle Package Body Definition members and Snowflake statements.
Create Package Body¶
Elements inside a Package Body are going to be extracted from the package. The package body will disappear so the Create Package Body statement is removed in the converted code.
Procedure Definition¶
Stored Procedures inside packages use the same transformations defined in the PL/SQL Translation Reference.
Oracle¶
Transformation with option 1¶
Transformation with option 2¶
Function Definition¶
Functions inside package bodies are converted into Snowflake stored procedures.
Oracle¶
Transformation with option 1¶
Transformation with option 2¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Other package body members¶
Please refer to the “other package members” section in Package declaration.
Using package members¶
Call of procedures inside packages¶
If the procedure is inside a package and the package is inside a schema, the call will be renamed.
Oracle¶
Transformation with option 1¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Transformation with option 2¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
With this option, the call of the procedures will be renamed accordingly to the rename of the procedure declaration. The schema name will be separated from the procedure name with a dot.
Snowflake¶
Package variables inside procedures¶
Note
Packages variables are transformed to session variables. Those variables are usable through the “Package variables helper”.
Note
This sample is using variables declared in packages Variables declaration section.
Oracle¶
Snowflake¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0053: Object may not work.
SSC-EWI-OR0049: Package constants in stateful package are not supported yet.
Procedures¶
Note
Some parts in the output code are omitted for clarity reasons.
Example 1: Basic Procedure Conversion
Oracle¶
Snowflake¶
Example 2: Procedure Conversion with basic statements: Declaration, Assignment, Cursor Declaration, FOR Cursor, Open, LOOP, CLOSE, IF,
Oracle¶
Snowflake¶
Call of procedures inside other procedure¶
Oracle¶
Snowflake¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0022: One or more identifiers in this statement were considered parameters by default.
SSC-FDM-OR0012: COMMIT and ROLLBACK statements require adequate setup to perform as intended.
SQL Language Elements¶
Note
Some parts in the output code are omitted for clarity reasons.
Cursor FOR LOOP¶
Note
You might also be interested in Cursor helper and Cursor declaration.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
OPEN, FETCH and CLOSE Statement¶
Note
You might also be interested in Cursor helper and Cursor declaration.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Warning
Transformation for the following lines corresponds to custom types, which are work in progress:
Currently the next statement is being emitted but the class is not being created yet. A warning will be applied in the future to all the uses of the unsupported custom types.
SQL Implicit Cursor¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
EXIT¶
Warning
Transformation for labels is a work in progress.
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Execute Immediate¶
Note
You might also be interested in EXEC helper
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Warning
Since the “RETURNING INTO” clause requires special analysis of the statement executed, its translation is planned to be delivered in the future.
Warning
Transformation for the following line corresponds to collection types, which is work in progress:
Currently the next statement is being emitted but the class is not being created yet. A warning will be applied in the future to all the uses of the unsupported custom types.
Also the following EXECUTE IMMEDIATE related with the BULK COLLECT into the sals variable, is also work in progress.
Errors and Exception Handling¶
Note
You might also be interested in Raise helper
Raise Helper Usage¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
When there is not OTHERS handler, SnowConvert AI uses the “default” case in the switch that throws the original Error Object.
Commit¶
Note
You might also be interested in EXEC helper
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
CASE¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
CASE in a variable assignment¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Call to external C or Java programs¶
Oracle¶
Snowflake¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0022: One or more identifiers in a specific statement are considered parameters by default.
SSC-EWI-0053: Object may not work.
SSC-EWI-0073: Pending Functional Equivalence Review.
SSC-EWI-OR0052: Exception declaration is handled by the raise function.
SSC-EWI-OR0072: Procedural Member not supported.
SSC-EWI-OR0075: Current of clause is not supported in Snowflake.
SSC-EWI-OR0104: Unusable collection variable.
SSC-FDM-OR0007: Snowflake does not support the versioning of objects. Developers should consider alternate approaches for code versioning.
SSC-FDM-OR0009: SQL IMPLICIT CURSOR VALUES MAY DIFFER.
SSC-FDM-OR0011: The Boolean argument was removed because the “add to stack” options is not supported.
SSC-FDM-OR0012: COMMIT and ROLLBACK statements require adequate setup to perform as intended.
DDL - DML Statements¶
Note
Some parts in the output code are omitted for clarity reasons.
Note
All statements use the EXEC helper.
SELECT¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
SELECT INTO¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
INSERT and INSERT INTO SELECT¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
DELETE¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
UPDATE¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
MERGE¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0022: One or more identifiers in a specific statement are considered parameters by default.
Synonyms¶
Synonyms used inside PL/SQL blocks are changed to the referenced object and the Schema will be added if necessary.
Implicit Schema added¶
When the procedure or function is inside a schema and the synonym is inside that schema, but it is being used without the schema, the converted code will add the schema.
Oracle¶
Snowflake¶
Schema of referenced object added¶
When the synonym references an object that is in a specific schema, the schema name will be added to the referenced object.
Oracle¶
Snowflake¶
Related EWIs¶
SSC-FDM-OR0005: Synonyms are not supported in Snowflake but references to this synonym were changed by the original object name.
SSC-FDM-OR0042: Date Type Transformed To Timestamp Has A Different Behavior.
Triggers¶
Warning
Triggers are not supported by Snowflake, and then they will not be migrated automatically.
Snowflake at this moment does not provide a direct mechanism for triggers, but some Snowflake features can be used to achieve similar results.
We recommend that you perform an analysis of your triggers, and classify them by purpose:
Audit Triggers: the intention of these triggers is to capture information and record the changes done on some tables into other tables.
Initialization Triggers: the intention of these triggers is to add some default values to the new records. They are usually before or after insert triggers
Business Rule Barrier Triggers: these usually apply for BEFORE/AFTER DELETE or UPDATE. These triggers are meant to create a barrier to avoid data entry or deletion that will break some business rules.
Instead of Triggers: used for example to allow inserts on views are not supported. The recommendation will be to turn that logic into a stored procedure and introduce calls whenever they were used for insert/delete/update operations.
Database Triggers: cannot be replicated, it is also recommended to encapsulate this logic into a stored procedure. But this logic will need to be manually invoked.
Generic After Triggers: for some after triggers, streams, and tasks can be leveraged see section below.
Audit Trigger¶
Before UPDATE triggers for audit cases like this cannot be handled directly. For the INSERT case you can use the default value case explained for the initialization trigger. However for the update case the only option will be to use a task as it is explained later for AFTER triggers. However the LAST_UPDATE will not be accurate, there will be an offset because the recorded modification will be at the time of task execution (for example if the tasks executes each 5min then the LAST_UPDATE will be recorded 5min later).
For UPDATE cases trying to capture the CURRENT_USER is not possible.
Other cases of AUDIT triggers are when they register changes of a table into an update table. Using the AFTER trigger technique describe later can be used but again USER information cannot be tracked and TIME information will not be accurate.
Initialization Trigger¶
For these triggers, you might use Snowflake Default column values for example for sequence values.
You can also use CURRENT_USER() and CURRENT_TIMESTAMP instead of USER or SYS_TIMESTAMP
This only applies for BEFORE INSERT or AFTER INSERT cases.
Business Rule Barrier¶
For these cases you will need to in-line the trigger actions after/before the DELETE or UPDATE is performed.
A task is not recommended here because tasks are run on an schedule, and then the row will already be modified.
Warning
This section shows a known workaround for partially implementing AFTER Triggers.
GENERIC AFTER TRIGGER¶
Example 1: Basic Trigger conversion¶
Oracle¶
Snowflake¶
Note
SnowConvert AI helpers Code removed from the example. You can find them here.
In-depth explanation for the snowflake code¶
Streams¶
These take care of storing the changes made to the table. Please note:
These will store the delta between the current table state, and the last offset stored by the stream itself. Please take this into account for billing purposes.
Notice that these do not store the information of updates, but rather store them as an insertion.
In the same manner, they cannot be configured to track only deletions or only updates, and thus they should have to be filtered in the procedure and the task itself (see below).
Procedures¶
These take care of running the trigger’s SQL statement(s). Please note:
There is a need to flush the stream, hence the new stream creation at the end of the procedure.
Any actions that need to be filtered (like AFTER-INSERTs-only triggers) will need to be filtered in the stored procedure itself.
Tasks¶
These take care of regularly verifying for stream changes and accordingly execute the trigger’s SQL statement(s). Please note:
The Tasks work on a schedule, an action does not trigger them. This means that there will be trigger scheduled checks with no data changes performed in the table.
Tasks cannot be configured to run more than once every sixty (60) seconds, as the minimum time is one (1) minute.
Once the stream has detected changes there will be, in the worst-case scenario, sixty (60) seconds of delay between the change detection and the trigger execution.
While adding the WHEN avoids Task execution, snowflake still adds Charge every time it is evaluated; and said Charge will be added to the bill when the trigger actually executes.
The Task needs a Warehouse to be executed in and will need to be manually set by the client.
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
TYPE attribute¶
Description¶
This chapter is related to transforming the TYPE attribute when it references a column, variable, record, collection, or cursor. The transformation involves getting the referenced item data type and replacing the referencing item TYPE attribute for the data type obtained.
Sample Source Patterns¶
TYPE attribute for columns¶
In this case, the referenced item is a column from a table created previously.
Oracle¶
Snowflake¶
TYPE attribute for variables¶
In this case, the referenced item is a variable declared previously.
Oracle¶
Snowflake¶
Note
Further information about FLOAT datatype can be found in FLOAT Data Type section
TYPE attribute for records¶
In this case, the referenced item is a record declared previously.
Oracle¶
Snowflake¶
In the example before, the variable which is referencing the record variable is changed to OBJECT as same as the record variable, and the variable which is referencing the record field is changed to the record field data type (NUMBER (38, 18)).
Warning
These changes don’t work for embedded records.
Note
Further information about records can be found in Collection & Records section.
TYPE attribute for collections¶
In this case, the referenced item is a collection variable, but since collections are not supported, the referencing item TYPE attribute is changed to VARIANT data type.
Oracle¶
Snowflake¶
TYPE attribute for cursors¶
In this case, the referenced item is a cursor variable, but since REF cursors are not supported, the referencing item TYPE attribute is changed to VARIANT data type.
Oracle¶
Snowflake¶
Note
For those cases when the data type of the referenced item cannot be obtained, the referencing item TYPE attribute is changed to VARIANT.
Knows Issues¶
1. Cursors and collections declarations are not supported.¶
Collection and cursor variable declarations are not supported yet so the referencing item TYPE attribute is changed to VARIANT and a warning is added in these cases.
2. Original data type could not be obtained.¶
When the referenced item data type could not be obtained the referencing item TYPE attribute is changed to VARIANT and a warning is added.
Related EWIs¶
SSC-EWI-0036: Data type converted to another data type.
SSC-EWI-0056: Create Type Not Supported.
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
SSC-EWI-0062: Custom type usage changed to variant.
SSC-EWI-OR0129: The statement below has usages of nested cursors.
SSC-FDM-0006: Number type column may not behave similarly in Snowflake.