Progress
Embedded SQL-92
Guide and Reference


Introduction to Cursors

A cursor is an SQL object that you associate with a specific SELECT statement. You associate a named cursor with a SELECT operation by declaring the cursor. To access the rows corresponding to the SELECT operation, follow these general steps:

  1. Use a DECLARE statement to associate a cursor with the query
  2. OPEN the cursor
  3. Use FETCH repeatedly on the opened cursor to retrieve all the rows in the result set
  4. CLOSE the cursor

You open a cursor with the OPEN statement. When you open a cursor, the query associated with the cursor executes, identifying the result set. This result set is referred to as the active set. An open cursor always points to a row in the active set; this row is referred to as the current row.

Use the FETCH statement to retrieve rows from an active set. Each time you execute a FETCH, the cursor moves by one row in the active set. A cursor can be in one of the two states: open or closed. When a cursor is in the open state, it is associated with an active set. It can point before the first row, at the current row, or after the last row. When the query operation is complete, you must close the cursor with a CLOSE statement. When a cursor is in the closed state, the cursor is no longer associated with the active set, although it remains associated with the SELECT statement.

The following sections explain the use of cursors for processing rows returned by a SELECT statement.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095