FETCH (Snowflake Scripting)¶
Uses the specified cursor to fetch one or more rows.
For more information on cursors, see Working with cursors.
Note
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
Syntax¶
FETCH <cursor_name> INTO <variable> [, <variable> ... ] ;
Where:
cursor_name
The name of the cursor.
variable
The name of the variable into which to retrieve the value of one column of the current row.
You should have one variable for each column defined in the cursor declaration.
The variable must already have been declared.
The variable’s data type must be compatible with the value to be fetched.
Usage notes¶
The number of
variable
s should match the number of expressions selected in theSELECT
clause of the cursor declaration.If you try to
FETCH
a row after the last row, you get NULL values.A RESULTSET or CURSOR does not necessarily cache all the rows of the result set at the time that the query is executed. FETCH operations can experience latency.
Examples¶
FETCH my_cursor_name INTO my_variable_name ;
For a more complete example of using a cursor, see the introductory cursor example.
An example using a loop is included in the documentation for FOR loops.