SnowConvert AI - Oracle - DML STATEMENTS¶
Description ¶
DML statement extensions differ from normal DML statements because they can use PL/SQL elements like collections and records. So far some of these elements are not supported by snowflake scripting. If one statement is not supported, an EWI will be added during the translation. Other DML statements will be translated as if they were not inside a procedure.
INSERT Statement Extension¶
Translation reference to convert Oracle INSERT Statement Extension to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
The PL/SQL extension to the SQL
INSERTstatement lets you specify a record name in thevalues_clauseof thesingle_table_insertinstead of specifying a column list in theinsert_into_clause.(Oracle PL/SQL Language Reference INSERT Statement Extension)
Snowflake INSERT INTO differs from Snowflake Scripting in variable constraints; needing to have the names preceded by a colon ‘:’ to bind the variables’ value.
Recommendations¶
Note
This code was executed for a better understanding of the examples:
Oracle¶
Snowflake¶
INSERT Statement Extension simple case¶
Oracle¶
Result¶
NUM |
WORD |
|---|---|
10 |
ten |
11 |
eleven |
Snowflake Scripting¶
Result¶
NUM |
WORD |
|---|---|
10 |
ten |
11 |
eleven |
Known Issues¶
1. Records are not supported by Snowflake Scripting¶
Since records are not supported by snowflake scripting, instead of using the VALUES record clause, it is necessary to change it into a SELECT clause and split the columns of the record. For more information please see the Record Type Definition Section.
MERGE Statement¶
Translation reference to convert Oracle MERGE statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
The
MERGEstatement is used to select rows from one or more sources for update or insertion into a table or view. It is possible to specify conditions to determine whether to update or insert into the target table or view. This statement is a convenient way to combine multiple operations. It lets you avoid multipleINSERT,UPDATE, andDELETEDML statements.MERGEis a deterministic statement. It is not possible to update the same row of the target table multiple times in the sameMERGEstatement. (Oracle PL/SQL Language Reference MERGE Statement)
Oracle MERGE Syntax¶
Snowflake Scripting MERGE Syntax¶
Sample Source Patterns¶
Sample auxiliary data¶
Note
This code was executed for a better understanding of the examples:
Oracle¶
Snowflake¶
MERGE Statement simple case¶
Oracle¶
Result¶
PERSON_ID |
FIRST_NAME |
LAST_NAME |
TITLE |
|---|---|---|---|
1 |
John |
Smith |
Mr |
2 |
Alice |
Jones |
Mrs. |
3 |
Jane |
Doe |
Miss |
4 |
Dave |
Brown |
Mr |
Snowflake¶
Result¶
PERSON_ID |
FIRST_NAME |
LAST_NAME |
TITLE |
|---|---|---|---|
1 |
John |
Smith |
Mr |
2 |
Alice |
Jones |
Mrs. |
3 |
Jane |
Doe |
Miss |
4 |
Dave |
Brown |
Mr |
MERGE Statement with DELETE and where clause¶
To find an equivalence for the DELETE statement and the where clause, it is necessary to reorder and implement some changes in the Snowflake merge statement.
Changed required:¶
Replace the Oracle’s DELETE where_clause with a new Snowflake’s matchedClause with the AND predicate statement
Replace the where_clause from the Oracle’s merge_insert_clause with an AND predicate statement in the Snowflake’s notMatchedClause
Oracle¶
Result¶
EMPLOYEE_ID |
BONUS |
|---|---|
153 |
180 |
154 |
175 |
155 |
170 |
159 |
180 |
160 |
175 |
161 |
170 |
164 |
72 |
165 |
68 |
166 |
64 |
167 |
62 |
171 |
74 |
172 |
73 |
173 |
61 |
179 |
62 |
Snowflake¶
Result¶
EMPLOYEE_ID |
BONUS |
|---|---|
153 |
180 |
154 |
175 |
155 |
170 |
159 |
180 |
160 |
175 |
161 |
170 |
164 |
72 |
165 |
68 |
166 |
64 |
167 |
62 |
171 |
74 |
172 |
73 |
173 |
61 |
179 |
62 |
Warning
In some cases the changes applied may not work as expected, like the next example:
Oracle¶
Result¶
PERSON_ID |
FIRST_NAME |
LAST_NAME |
TITLE |
|---|---|---|---|
1 |
John |
Smith |
Mr |
4 |
Dave |
Brown |
Mr |
Snowflake¶
Result¶
PERSON_ID |
FIRST_NAME |
LAST_NAME |
TITLE |
|---|---|---|---|
1 |
John |
Smith |
Mr |
2 |
Alice |
Jones |
Mrs. |
4 |
Dave |
Brown |
Mr |
Known Issues¶
1. Oracle’s error_logging_clause is not supported¶
There is no equivalent for the error logging clause in Snowflake Scripting.
2. Changed applied do not work as expected¶
Sometimes, the changes applied to achieve the functional equivalence between Oracle’s merge statement and Snowflake’s do not work as expected.
Related EWIs¶
SSC-FDM-0006: Number type column may not behave similarly in Snowflake.
SSC-FDM-OR0018: Merge statement may not work as expected
SELECT INTO Statement¶
Translation reference to convert Oracle SELECT INTO statement to Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
The
SELECTINTOstatement retrieves values from one or more database tables (as the SQLSELECTstatement does) and stores them in variables (which the SQLSELECTstatement does not do). (Oracle PL/SQL Language Reference SELECT INTO Statement)
Oracle SELECT INTO Syntax¶
Oracle Into Clause Syntax¶
Oracle Bulk Collect Syntax¶
Snowflake Scripting SELECT INTO Syntax¶
Sample Source Patterns¶
Sample auxiliary data¶
Note
This code was executed for a better understanding of the examples:
Oracle¶
Snowflake¶
SELECT INTO Statement simple case¶
Oracle¶
Result¶
AUX_NUM |
AUX_WORD |
|---|---|
1 |
one |
Snowflake Scripting¶
Result¶
Known Issues¶
1. BULK COLLECT INTO is not supported¶
Snowflake Scripting does not support the BULK COLLECT INTO clause. However, it is possible to use ARRAY_AGG to construct a new variable. For more information please see the Collection Bulk Operations Section.
2. Collections and records are not supported¶
Snowflake Scripting does not support the use of collections nor records. It is possible to migrate them using Semi-structured data types as explained in Collections and records.
Related EWIs¶
No related EWIs.
Work around to simulate the use of Records¶
Warning
This page is deprecated but was left for compatibility purposes. If you want to see the updated section, please refer to Collections And Records
Description¶
This section describes how to simulate the behavior of Oracle records in SELECT and INSERT Statements, using RESULTSET and CURSORS of Snowflake Scripting.
Snowflake Scripting RESULTSET and CURSOR¶
Snowflake RESULTSET Syntax¶
Recommendations¶
Note
For the following examples, this code was executed to better understanding of the examples:
Oracle¶
Snowflake¶
Using RESULTSET and Cursors instead of Records¶
Oracle¶
Result¶
AUX_NUM |
AUX_WORD |
|---|---|
1 |
one |
Snowflake¶
using cursor
Result¶
AUX_NUM |
AUX_WORD |
|---|---|
1 |
one |
Known Issues¶
1. Limitation in the use of RESULTSET¶
RESULTSET is very limited in its use. If table(result_scan(last_query_id())) statement, should be used just after the RESULTSET’s query is executed. For further information check this link.
Related EWIs¶
SSC-EWI-0036: Data type converted to another data type.
SSC-EWI-0056: Create Type Not Supported.