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.

See also:

DECLARE, OPEN, CLOSE

Syntax

FETCH <cursor_name> INTO <variable> [, <variable> ... ] ;
Copy

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 variables should match the number of expressions selected in the SELECT 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 ;
Copy

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.