SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Introduction
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
1-6
Using Dynamic SQL
•
Positioned UPDATE statement
EXEC SQL UPDATE persnl.customer
SET credit = 'A1'
WHERE CURRENT OF get_customer;
The UPDATE statement updates values in a single row at the current position of
the cursor. The cursor remains positioned on the current row.
•
CLOSE statement
EXEC SQL CLOSE get_customer;
The CLOSE statement releases the result table established by OPEN for the
cursor.
See also Section 6, Static SQL Cursors.
Using Dynamic SQL
A static SQL statement is embedded in a host program and known at the time the host
program is preprocessed. A dynamic SQL statement is either prepared dynamically
with the PREPARE statement or executed through the EXECUTE IMMEDIATE
statement.
Sometimes an SQL statement is not known when the program is coded—it is
generated during program execution. In this case, you code a host variable with
character string data type as a placeholder for an SQL statement within a PREPARE
statement.
The source form of the SQL statement is a character string passed to NonStop
SQL/MX for compilation with PREPARE. The character string must be a valid SQL
statement. To construct the SQL statement, the program usually requires some input
from a user.
A dynamic SQL program typically includes declarations and statements to:
•
Declare a host variable as a place to store a dynamic SQL statement.
•
Construct the SQL statement and store the statement in the declared host variable.
•
Prepare the SQL statement.
•
Execute the prepared statement.
See Section 10, Dynamic SQL With Descriptor Areas.
A dynamic SQL program can also use either SQL descriptor areas or dynamic SQL
cursors. Both techniques allow the user to specify SQL statements at run time.
Using Descriptor Areas for Dynamic SQL
A dynamic SQL program that uses descriptor areas typically includes declarations and
statements to:
•
Declare a host variable as a place to store a dynamic SQL statement.