Firebird Documentation IndexFirebird 3.0.6 Release NotesProcedural SQL (PSQL) → Scrollable (Bi-directional) Cursor Support
Firebird Home Firebird Home Prev: DDL triggersFirebird Documentation IndexUp: Procedural SQL (PSQL)Next: Exceptions with parameters

Scrollable (Bi-directional) Cursor Support

Dmitry Yemanov

Cursor Syntax for PSQL

Instead of just fetching rows sequentially in a forward direction, scrollability allows flexible navigation through an open cursor set both backwards and forwards. Rows next to, prior to and relative to the current cursor row can be targetted. In PSQL, a scrollable cursor can be operated on directly. API support is available to enable DSQL applications to fetch rows in a similar manner.

Cursor Syntax for PSQL

To declare a cursor:

DECLARE <name> SCROLL CURSOR FOR ( <select expression> )
      

To fetch forward:

FETCH <cursor name> [INTO <var name> [, <var name> ...]];
      

To fetch in any direction:

FETCH {NEXT | PRIOR | FIRST | LAST | ABSOLUTE <n> | RELATIVE <n>}
  FROM <cursor name> [INTO <var name> [, <var name> ...]];
      

See also Scrollable Cursor Support for DSQL in the chapter entitled [Changes to the Firebird API and ODS]. The section entitled Scrollable Cursor Usage explains a little more about the usage of the various FETCH options.

Notes

  1. When a scrolling option is omitted, NO SCROLL is implied (i.e., the cursor is opened as forward-only). This means that only FETCH [NEXT FROM] commands can be used. Other commands will return an error.

  2. Scrollable cursors are internally materialized as a temporary record set, thus consuming memory/disk resources, so this feature should be used only when really necessary.

Prev: DDL triggersFirebird Documentation IndexUp: Procedural SQL (PSQL)Next: Exceptions with parameters
Firebird Documentation IndexFirebird 3.0.6 Release NotesProcedural SQL (PSQL) → Scrollable (Bi-directional) Cursor Support