SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Dynamic SQL
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
9-7
Deallocate the Prepared Statement
Example
This statement uses both input parameters and output variables:
EXEC SQL EXECUTE sqlstmt 
 USING :in_empnum 
 INTO :hv_empnum,:hv_firstname,:hv_lastname,
 :hv_salary INDICATOR :hv_salary_i;
You must specify the indicator variable in the INTO argument list for columns that allow 
null.
Deallocate the Prepared Statement
When you are finished with the dynamic SQL statement, deallocate the resources used 
by the prepared statement. See the DEALLOCATE PREPARE statement in the 
SQL/MX Reference Manual.
Example
EXEC SQL DEALLOCATE PREPARE sqlstmt; 
...
Using EXECUTE IMMEDIATE
If the dynamic SQL statement does not contain input or output parameters and you are 
planning to execute it only once, use the EXECUTE IMMEDIATE statement to prepare 
and execute in one step. In this case, the user provides the SQL statement. Otherwise, 
you could code the SQL statement as static SQL in your program.
Use this general syntax: 
For complete syntax, see the EXECUTE IMMEDIATE statement in the SQL/MX 
Reference Manual.
You must specify the host variable that contains the statement to be prepared and 
executed in the EXECUTE IMMEDIATE statement.
Example
strcpy (hv_sql_statement, "UPDATE employee" 
 " SET salary = salary * 1.1" 
 " WHERE jobcode = 1234");
EXEC SQL EXECUTE IMMEDIATE :hv_sql_statement; 
The host variable hv_sql_statement contains the SQL statement.
EXECUTE IMMEDIATE SQL-statement-variable 
C
C
C










