Cursor scoping rules

The rules that govern the initial scope of a cursor differ, depending on whether the cursor is static or dynamic. However, after a static cursor is opened or a dynamic cursor is declared, the scoping rules for both types of cursors are the same. The rules are as follows:

Until a static cursor is open, its scope is limited to the file where the cursor was declared. Any statement that opens the static cursor must be in this file. After a static cursor is open, its scope is limited to the connection on which the cursor was opened.

A dynamic cursor does not exist until it is declared. After it is declared, its scope is limited to the connection on which it was declared.

A cursor name can be open on more than one connection at a time.

Statements that fetch, update, delete, or close a cursor can appear in files other than the one where the cursor is declared. Such statements, however, must execute on the connection where the cursor was opened.

Cursor names must be unique within a program. If, at runtime, an application attempts to declare two identically named cursors, the application fails. The following error message results:

There is already another cursor with the name ‘XXX’.