SnowConvert AI - Oracle - CURSOR¶
Description¶
Danger
This section covers the Translation Reference for Oracle Explicit Cursor. For Oracle Cursor Variables there is no equivalent in Snowflake Scripting.
Note
Some parts in the output code are omitted for clarity reasons.
Cursors are pointers that allow users to iterate through query results. For more information, see the Oracle Cursors documentation.
Oracle Cursor Syntax¶
Cursor Definition
Cursor Open
Cursor Fetch
Cursor Close
Cursor Attributes
Cursor FOR Loop
Snowflake Scripting has support for cursors, however, they have fewer functionalities compared to Oracle. For more information, see the Snowflake Scripting cursors documentation.
Snowflake Scripting Cursor Syntax¶
Cursor Declaration
Cursor Open
Cursor Fetch
Cursor Close
Cursor FOR Loop
Sample Source Patterns¶
1. Basic cursor example¶
Oracle Cursor Example¶
Snowflake Scripting Cursor Example¶
2. Explicit Cursor For Loop¶
Oracle Explicit Cursor For Loop Example¶
Snowflake Scripting Explicit Cursor For Loop Example¶
3. Implicit Cursor For Loop¶
Oracle Implicit Cursor For Loop Example¶
Snowflake Scripting Implicit Cursor For Loop Example¶
4. Parameterized Cursor¶
You can use “?” In the filter condition of the cursor at the declaration section define the bind variable. While opening the cursor we can add the additional syntax “USING <bind_variable_1 >” to pass the bind variable.
Below are some examples of scenarios that can occur in the use of parameters in cursors:
4.1 Basic Cursor Parameterized Example¶
Oracle Parameterized Cursor Example¶
Snowflake Parameterized Cursor Example¶
4.2 Parameterized Cursors With Multiple Sending Parameters¶
Oracle Parameterized Cursor Example¶
Snowflake Parameterized Cursor Example¶
4.3 Parameterized Cursors With Use Of Procedure Parameters In Query¶
Oracle Parameterized Cursor Example¶
Snowflake Parameterized Cursor Example¶
5. Using Cursors In Fetch And For Loop¶
Cursors can be controlled through the use of the FOR statement, allowing each and every record of a cursor to be processed while the FETCH statement puts, record by record, the values returned by the cursor into a set of variables, which may be PLSQL records
5.1 Cursors For Loop¶
Oracle Cursor For Loop Example¶
Snowflake Cursor For Loop Example¶
5.2 Cursors Fetch¶
Oracle Cursor Fetch Example¶
Snowflake Cursor Fetch Example¶
Known Issues¶
1. RETURN clause is not supported in Snowflake Scripting Cursor Declaration¶
The Cursor Declaration for Snowflake Scripting does not include this clause. It can be removed from the Oracle Cursor definition to get functional equivalence.
2. OPEN statement cannot pass values for declared arguments¶
Even though arguments can be declared for a cursor, their values cannot be assigned in Snowflake Scripting. The best alternative is to use the USING clause with bind variables.
3. FETCH statement cannot use records¶
Snowflake Scripting does not support records. However, it is possible to migrate them using the OBJECT data type and the OBJECT_CONSTRUCT() method. For more information please see the Record Type Definition Section.
4. FETCH BULK COLLECT INTO clause is not supported in Snowflake Scripting¶
Snowflake Scripting does not support the BULK COLLECT INTO clause. However, it is possible to use ARRAY_AGG along with a temporal table to construct a new variable with the data corresponding to the Cursor information. For more information please see the Collection Bulk Operations Section.
5. Cursor attributes do not exist in Snowflake Scripting¶
Oracle cursors have different attributes that allow the user to check their status like if it is opened or the amount of fetched rows, however, these attributes regarding the cursor status do not exist in Snowflake Scripting.
6. The cursor’s query does not have access to the procedure’s variables and parameters¶
In Oracle, the query in the cursor declaration has access to procedure variables and parameters but in Snowflake Scripting, it does not. The alternative to this is to use the USING clause with bind variables.
7. %NOTFOUND attribute is not supported in Snowflake Scripting Cursor¶
In Oracle can be used, before the first fetch from an open cursor, cursor_name%NOTFOUND returns TRUE if the last fetch failed to return a row, or FALSE if the last fetch returned a row. Snowflake Scripting does not support the use of this attribute instead it can be validated if the variable assigned to the cursor result contains values
CURSOR DECLARATION¶
Note
Non-relevant statement.
Warning
Notice that this statement removed from the migration; because it is a non-relevant syntax. It means that it is not required in Snowflake.
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
This section explains the translation of the declaration of cursors in Oracle. For more information review the following documentation about procedures and cursors in Oracle.
Sample Source Patterns¶
CURSOR DECLARATION¶
Notice that in this example the CURSOR statement has been deleted. This is a non-relevant syntax in the transformation targeted to Snowflake.
Oracle¶
Snowflake¶
Known Issues¶
No issues were found.
Related EWIs¶
No related EWIs.
Cursor Variables¶
Translation reference for cursor variables and the OPEN FOR statement
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
A cursor variable is like an explicit cursor that is not limited to one query.
(Oracle PL/SQL Language Reference Cursor Variable Declaration)
Oracle Syntax¶
Ref cursor type definition
Cursor variable declaration
OPEN FOR statement
Warning
Snowflake Scripting has no direct equivalence with cursor variables and the OPEN FOR statement, however, they can be emulated with different workarounds to get functional equivalence.
Sample Source Patterns¶
1. OPEN FOR statement with dynamic SQL inside a VARCHAR variable¶
Oracle Example¶
Snowflake Scripting Example¶
2. OPEN FOR statement with dynamic SQL inside a string literal.¶
Oracle Example¶
Snowflake Scripting Example¶
3. OPEN FOR statement with SELECT statement¶
Oracle Example¶
Snowflake Scripting Example¶
4. Cursor Variable declared with REF CURSOR type¶
Oracle Example¶
Snowflake Scripting Example¶
5. OPEN FOR statement with USING clause¶
Oracle Example¶
Snowflake Scripting Example¶
Known Issues¶
No issues were found.
Related EWIs¶
SSC-EWI-0030: The statement below has usages of dynamic SQL.
SSC-EWI-0058: Functionality is not currently supported by Snowflake Scripting.
PARAMETRIZED CURSOR¶
Parametrized Cursor is not supported by Snowflake Scripting
Note
Some parts in the output code are omitted for clarity reasons.
Description¶
Oracle supports parameters for cursors that are declared. However, Snowflake Scripting does not support this feature, so the declaration and the usage of the cursor are not possible.
Example Code¶
Oracle¶
Snowflake¶
Recommendations¶
Try using bindings for the query in the cursor and open the cursor with the
USINGclause. Keep in mind that a parameter that is used multiple times on a single cursor may require passing the variable multiple times in theUSINGclause.
Snowflake Query¶
Manually change the cursor to use bindings.
If you need more support, you can email us at snowconvert-support@snowflake.com
Related EWIs¶
SSC-PRF-0004: This statement has usages of cursor for loop.
Workaround for cursors using parameters or procedure variables¶
Description¶
This section describes how to simulate the usage of cursor parameters and procedure variables inside the query of a cursor. The name of the variables or parameters is replaced with bindings using the ? sign. Then, when the cursor is opened, the values should be passed with the USING clause.
Note
Cursor with local variables¶
Use bindings for the query in the cursor for variable or procedure parameter used and open the cursor with the USING clause.
Oracle Cursor¶
Snowflake Scripting Cursor¶
Cursor with parameters¶
Use bindings for the query in the cursor for each parameter used and open the cursor with the USING clause. Keep in mind that a parameter that is used multiple times on a single cursor may require passing the variable multiple times in the USING clause.
Oracle Cursor¶
Snowflake Scripting Cursor¶
Related EWIs¶
SSC-PRF-0004: This statement has usages of cursor for loop