Opening cursors

To retrieve the contents of selected rows, you must first open the cursor. The open statement executes the select statement associated with the cursor in the declare statement.

The open statement’s syntax for opening a cursor is:

exec sql open cursor_name [ROW_COUNT = size] end-exec.

NoteROW_COUNT should be specified with cursors when arrays are used as host variables and multi-row retrieval is required.

After you declare a cursor, you can open it wherever you can issue a select statement. When the open statement executes, Embedded SQL substitutes the values of any host variables referenced in the declare cursor statement’s where clause.

The number of cursors you may have open depends on the resource demands of the current session. Adaptive Server does not limit the number of open cursors. However, you cannot open a currently open cursor. Doing so results in an error message.

While an application executes, you can open a cursor as many times as necessary, but you must close it before reopening it. You need not retrieve all the rows from a cursor result set before retrieving rows from another cursor result set.