FETCH (Snowflake Scripting)¶
Uses the specified cursor to fetch one or more rows.
For more information on cursors, see Working with Cursors.
This Snowflake Scripting construct is valid only within a Snowflake Scripting block.
FETCH <cursor_name> INTO <variable> [, <variable> ... ] ;
The name of the cursor.
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.
The number of
variables should match the number of expressions selected in the
SELECTclause of the cursor declaration.
If you try to
FETCHa 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.
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.