SnowConvert AI - Oracle - Javascript Helpers¶
In this section you will find the helper functions used inside procedures that are used to achieve functional equivalence of some Oracle features that are not supported natively in Snowflake.
Between operator helper¶
Between Operator Helper Function Definition¶
Concat Value Helper¶
Note
This helper also uses IS NULL helper.
Concat Helper Function Definition¶
Helper method used to concatenate values in a JavaScript Template Literal. This is necessary to check if values are null or not. Oracle handles null values as empty strings in concatenations.
Cursor Helper¶
Note
You might also be interested in:
Note
This helper also uses Raise helper and EXEC helper.
Cursor Helper Function Definition¶
EXEC Helper¶
Note
EXEC helper depends on IS NULL helper.
Syntax¶
EXEC(stmt)
EXEC(stmt, binds[])
EXEC(stmt, opts{})
EXEC(stmt, binds[], opts{})
Parameters¶
stmt¶
The string of the SQL statement to execute.
binds (optional)¶
An array with the values or the variables to bind into the SQL statement.
opts (optional)¶
This is a Javascript object to describe how the values returned by the exec should be formatted, this is used for SELECT statements.
Valid arguments for opts parameter¶
The following tables describe, how arguments should be sent to opts parameter in EXEC call:
Options when a query returns a single row¶
opts |
description |
|---|---|
{ } |
When opts is empty or not sent to exec call, the data will be returned inside an array. |
{vars: 0} |
This has the same effect as the default option. It will return the data inside an array. |
{vars: 1} |
This is used when a query returns just one column and one row. EXEC will return the value directly. This is equivalent to EXEC(stmt)[0] |
{rec:recordVariable} |
Used when you want to store the values returned by the query inside a record. Translation of records is described in Records translation reference. Record variable should be passed as an argument. |
{row: 1} |
This option returns a copy of ResultSet, this means that the object returned contains the methods described in ResultSet Snowflake documentation. |
Options when a query returns multiple rows¶
opts |
Description |
|---|---|
{row:2} |
With this option, it always returns a copy of the ResultSet regardless of the number of rows returned by the EXEC. |
General options¶
opts |
Description |
|---|---|
{sql:0} |
It makes sure that the SQL implicit Cursor attribute is not modified after executing the statement. |
EXEC Helper Function Definition¶
Usage Samples¶
The following code examples illustrates how EXEC works.
EXEC simple case¶
Oracle¶
Snowflake¶
EXEC with bindings¶
Oracle¶
Snowflake¶
EXEC with options¶
Oracle¶
Snowflake¶
For the following sample, EXEC call returns [12], with object destructuring ID_VAR stores 12:
The following two EXEC calls are alternative ways for the previous sample without object destructuring:
Object destructuring also works with bindings as you may note on these statements (EXEC call returns [12, “MOUSE”] values):
To obtain the actual result set returned by Snowflake, you can use this syntax:
EXEC with record types¶
Note
You might be interested in Records transformation.
Oracle¶
Snowflake¶
Warning
This is still a work in progress. The transformation to properly store the record values will be:
Known Issues¶
No issues were found.
Implicit Cursor attribute helper¶
Overview¶
These are the attributes that you can use inside Snowflake stored procedures using this helper:
FOUND
NOTFOUND
ROWCOUNT
ISOPEN
In Snowflake code, inside the procedures, you will find the initialization of these attributes:
The attribute ISOPEN is always false, just like in Oracle.
Usage Samples¶
Oracle¶
Snowflake¶
Note
SQLCODE and SQLERRM are converted into helper variables with the same name and are bound in the same way as the cursor variables.
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
IS NULL Helper¶
IS NULL Helper Function Definition¶
This helper method is used to transform the NULL predicate. It is also used by other helpers to check if a value is null. This is necessary to handle values like NaN or empty strings as nulls.
Oracle handles empty strings as null values. This helper takes that into account.
Like operator Helper¶
Like Operator Helper Function Definition¶
Package variables helper¶
Note
You might also be interested in variables declaration and package variables inside procedures.
Package variables Helper Function Definition¶
Note
Helper depends on IS NULL helper
When a package variable is used inside a procedure, the following helper will be generated:
When a package variable is used inside a procedure, the following helper will be generated:
A helper instance is created for each package used to access its variables. Variables will be qualified with the name of the package if they are not qualified with it.
At the end of the procedure, the state of the variables used will be saved using the helper.
Note that in the following statement, name of the variable will change to match the package name:
Raise Helper¶
Note
You might be interested in Errors and Exception Handling.
Raise Helper Function Definition¶
ROWTYPE Helper¶
Note
You might be interested in ROWTYPE Record Declaration.