NonStop SQL/MP Reference Manual

Table Of Contents
NonStop SQL/MP Reference Manual142115
P-26
Examples—PREPARE
You can have up to 20 prepared statements in a SQLCI session. (Programs can have
more prepared statements.)
Examples—PREPARE
The following program fragment uses PREPARE to compile an SQL statement
stored in :INTEXT, a varying length character variable. The program constructs the
SQL statement (not shown), compiles it (naming it OPERATION1), and then
executes it.
...
EXEC SQL
PREPARE OPERATION1 FROM :INTEXT;
...
EXEC SQL
EXECUTE OPERATION1;
...
The following SQLCI example prepares a SELECT statement (naming it
EMPCOM) and then enters the DISPLAY STATISTICS command to display the
preparation statistics:
>> PREPARE EMPCOM FROM
+> "SELECT FIRST_NAME, LAST_NAME, DEPTNUM"
+> & "FROM PERSNL.EMPLOYEE WHERE DEPTNUM <> 1500"
+> & "AND SALARY <= (SELECT AVG (SALARY)"
+> & "FROM PERSNL.EMPLOYEE WHERE DEPTNUM = 1500)";
--- SQL command prepared.
>> DISPLAY STATISTICS;
The following SQLCI example prepares an INSERT statement with parameters,
then supplies parameter values with the EXECUTE:
>> PREPARE EMPIN FROM "INSERT INTO PERSNL.EMPLOYEE"
+> &" VALUES (?, ?, ?, ?, ?, ?);
---SQL command prepared.
>> EXECUTE EMPIN USING 66, "AMY", "RYAN", 3100, 300, 50500;
WHERE DEPTNUM = 1500) ";