CURSOR
Translation reference to convert Teradata CURSOR statement to Snowflake Scripting
Description
A cursor is a data structure that is used by stored procedures at runtime to point to a resultset returned by an SQL query. For more information check here.
DECLARE cursor_name [ SCROLL | NO SCROLL ] CURSOR
[
WITHOUT RETURN
|
WITH RETURN [ ONLY ] [ TO [ CALLER | CLIENT ] ]
]
FOR
cursor_specification [ FOR [ READ ONLY | UPDATE ] ]
|
statement_name
;FETCH [ [ NEXT | FIRST ] FROM ] cursor_name INTO
[ variable_name | parameter_name ] [ ,...n ]
;OPEN cursor_name
[ USING [ SQL_identifier | SQL_paramenter ] [ ,...n ] ]
;Sample Source Patterns
Setup Data
The following code is necessary to execute the sample patterns present in this section.
Basic Cursor
Teradata
Snowflake Scripting
Single Returnable Cursor
The following procedure is intended to return one result set since it has the DYNAMIC RESULT SETS 1 property in the header, the cursor has the WITH RETURN property and is being opened in the body.
Teradata
Snowflake Scripting
Multiple Returnable Cursors
The following procedure is intended to return multiple results when DYNAMIC RESULT SETS property in the header is greater than 1, the procedure has multiple cursors with the WITH RETURN property and these same cursors are being opened in the body.
Teradata
Snowflake Scripting
Cursos With Binding Variables
The following cursor uses binding variables as the were condition to perform the query.
Teradata
Snowflake Scripting
Cursor For Loop
It is a type of loop that uses a cursor to fetch rows from a SELECT statement and then performs some processing on each row.
Teradata
Snowflake Scripting
Cursor Fetch inside a Loop
It allows one to retrieve rows from a result set one at a time and perform some processing on each row.
Teradata
Snowflake Scripting
Known Issues
The following parameters are not applicable in Snowflake Scripting.
1. Declare
[ SCROLL/NO SCROLL ] Snowflake Scripting only supports FETCH NEXT.
[ READ-ONLY ] This is the default in Snowflake Scripting.
[ UPDATE ].
2. Fetch
[ NEXT ] This is the default behavior in Snowflake Scripting.
[ FIRST ].
Related EWIs
MSCEWI1081: Snowflake Scripting procedures cannot return more than one result set
MSCCP0003: This statement has usages of cursor for loop
MSCCP0006: Fetch inside a loop is considered a complex pattern, this could degrade Snowflake performance
Last updated
Was this helpful?