SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Dynamic SQL Cursors
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
11-5
Initialize the Dynamic Input Parameters
•
In listing order, before other SQL statements that refer to the cursor, including the
OPEN, FETCH, DELETE, UPDATE, and CLOSE statements
•
Within the scope of other SQL statements that refer to the cursor
Initialize the Dynamic Input Parameters
Initialize the dynamic input parameters you specified in the cursor specification in the
DECLARE CURSOR declaration.
You must initialize the host variables before you execute the OPEN statement. The
OPEN statement uses the values of the input parameters to establish the result table
and position the cursor before the first row of the table.
Open the Cursor
The OPEN statement determines the result table and positions the cursor before the
first row of the table.
Use this general syntax:
For complete syntax, see the OPEN statement in the SQL/MX Reference Manual.
You can also use this syntax for an OPEN statement that uses an input descriptor area
(that has been allocated, described, and initialized with the appropriate input parameter
values):
OPEN cursor-name USING SQL DESCRIPTOR descriptor-name
Retrieve the Values
The FETCH statement positions the cursor at the next row of the result table and
transfers the values defined in the query expression of the DECLARE CURSOR
statement into the corresponding host variables.
Use this general syntax:
For complete syntax, see the FETCH statement in the SQL/MX Reference Manual.
The cursor must be open when the FETCH statement executes. The FETCH
statement must also execute within the scope of all other SQL statements that refer to
the cursor, including DECLARE CURSOR, OPEN, DELETE, UPDATE, and CLOSE
statements.
OPEN cursor-name USING variable-spec [,variable-spec]...
FETCH cursor-name INTO :hostvar [,:hostvar ]...