Declaring a Cursor
To declare a cursor, you associate a cursor name with a retrieve statement. You must declare a cursor before you can use it. In your source code, the declare statement must appear before the first use of the cursor; the declare statement is used by the preprocessor and does not generate executable code.
The syntax for declaring a cursor is
## declare cursor cursor_name for
## retrieve_statement
## for [deferred | direct] update of column {, column}
The
cursor_name can be either a literal or a host language character string variable assigned a valid cursor name at runtime. Cursor names must obey the naming conventions described in
Object Names on page 1. The retrieve clause used in a declare statement must observe the correct QUEL syntax.
The for update clause allows you to specify the manner in which the DBMS Server updates the tables that are referenced by the cursor. If you intend only to delete rows, you do not need to declare the cursor for update. The default mode for the for update clause is deferred. In deferred mode, the updates you make using the cursor are not written until you close the cursor. Only one cursor can be open for deferred update at any time. In direct mode, the updates you make using the cursor are written immediately. If you write a change that affects the sequence of rows (for example, you modify a key field), the next retrieve statement returns the next row in the new sequence.
No data is retrieved as a result of the declare cursor statement. Data is retrieved when you open the cursor and issue a retrieve cursor statement.
Last modified date: 01/30/2023