Opening a row cursor
After you declare a row cursor, you need to tell Db2 that you are ready to process the first row of the result table. This action is called opening the cursor.
About this task
To open a row cursor, execute the OPEN statement in your
program. Db2 then uses the SELECT
statement within DECLARE CURSOR to identify a set of rows. If you
use host variables in the search condition of that SELECT statement, Db2 uses the current value of
the variables to select the rows. The result table that satisfies
the search condition might contain zero, one, or many rows. An example
of an OPEN statement is:
EXEC SQL
OPEN C1
END-EXEC.If you use the CURRENT DATE, CURRENT TIME, or CURRENT TIMESTAMP special registers in a cursor, Db2 determines the values in those special registers only when it opens the cursor. Db2 uses the values that it obtained at OPEN time for all subsequent FETCH statements.
Two factors that
influence the amount of time that Db2 requires
to process the OPEN statement are:
- Whether Db2 must perform any sorts before it can retrieve rows
- Whether Db2 uses parallelism to process the SELECT statement of the cursor