SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-163
COBOL Examples of PREPARE
COBOL Examples of PREPARE
Prepare and execute an INSERT statement:
...
MOVE "INSERT INTO SALES.CUSTOMER
- " (CUSTNUM, CUSTNAME, STREET, CITY, STATE, POSTCODE)
- " VALUES (1120, 'EXPERT MAILERS', '5769 N.25TH PLACE',
- " 'PHOENIX', 'ARIZONA', '85016')"
TO stmt-buffer.
...
EXEC SQL PREPARE ins_cust FROM :stmt-buffer END-EXEC.
...
EXEC SQL EXECUTE ins_cust END-EXEC.
...
Prepare and execute an UPDATE statement with dynamic input parameters:
...
MOVE "UPDATE SALES.CUSTOMER SET CREDIT = ? "
& " WHERE CUSTNUM = CAST(? AS NUMERIC(4) UNSIGNED)")"
TO stmt-buffer.
...
EXEC SQL PREPARE upd_cust FROM :stmt-buffer END-EXEC.
...
* Input values for parameters into host variables
ACCEPT in-credit.
ACCEPT in-custnum.
...
EXEC SQL EXECUTE upd_cust
USING :in-credit, :in-custnum
END-EXEC.
...
This example uses extended statement names:
...
MOVE "ins_cust1" TO stmt.
EXEC SQL PREPARE :stmt FROM :stmt-buffer END-EXEC.
EXEC SQL EXECUTE :stmt END-EXEC.
...
MOVE "ins_cust2" TO stmt.
EXEC SQL PREPARE :stmt FROM :stmt-buffer END-EXEC.
EXEC SQL EXECUTE :stmt END-EXEC.