FETCH

Uses the specified cursor to fetch one or more rows.

For more information on cursors, see Working with Cursors.

See also

DECLARE, OPEN, CLOSE

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 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 ;

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.

Back to top