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-4
Declare Required Host Variables
Declare Required Host Variables
In an SQL Declare Section, declare the host variable you specify as the statement
name for the cursor specification within the DECLARE CURSOR statement. You must
also declare host variables used in the OPEN statement for dynamic input parameters.
Declare required host variables:
•
Before the PREPARE statement for the cursor specification
•
Before the OPEN statement using the values for dynamic input parameters for the
cursor specification
•
Within the same scope as the SQL statements that refer to them
Prepare the Cursor Specification
In dynamic SQL, a host variable contains the query expression that serves as the
cursor specification. Initialize the host variable before you execute the PREPARE
statement for the cursor specification. The query expression might contain a dynamic
input parameter.
After you initialize the host variable with the cursor specification, use the PREPARE
statement to compile the cursor specification and associate the compiled statement
with a statement name. Use the statement name in the DECLARE CURSOR
statement.
Use this general syntax:
For complete syntax, see the PREPARE statement in the SQL/MX Reference Manual.
Declare the Cursor
A dynamic DECLARE CURSOR statement names a cursor and associates it with a
statement name. Within a dynamic DECLARE CURSOR statement, both the cursor
name and statement name can be provided at run time by the values of host variables.
The statement name identifies the cursor specification already prepared within the
same scope as the DECLARE CURSOR statement.
Use this general syntax:
For complete syntax, see the DECLARE CURSOR Declaration in the SQL/MX
Reference Manual.
Code a dynamic DECLARE CURSOR statement in your program:
PREPARE statement-name FROM :cursor-specification
DECLARE {cursor-name | ext-cursor-name}
CURSOR FOR statement-name