Neoview SQL Reference Manual (R2.5)

Considerations for EXECUTE
Scope of EXECUTE
A statement must be compiled by PREPARE before you EXECUTE it, but after it is compiled,
you can execute the statement multiple times without recompiling it. The statement must have
been compiled during the same Neoview Command Interface session as its execution.
Examples of EXECUTE
Use PREPARE to compile a statement once, and then execute the statement multiple times
with different parameter values. This example uses the SET PARAM command to set
parameter values for named parameters (represented by ?param-name) in the prepared
statement.
SQL>prepare findemp from
+>select * from persnl.employee
+>where salary > ?sal and jobcode = ?job;
--- SQL command prepared.
SQL>set param ?sal 40000.00
SQL>set param ?job 450;
SQL>execute findemp;
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
------ --------------- -------------- ------- ------- --------
232 THOMAS SPINNER 4000 450 45000.00
--- 1 row(s) selected.
SQL>set param ?sal 20000.00
SQL>set param ?job 300
SQL>execute findemp;
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
------ --------------- -------------- ------- ------- --------
75 TIM WALKER 3000 300 32000.00
89 PETER SMITH 3300 300 37000.40
...
--- 13 row(s) selected.
Specify literal values in the USING clause of the EXECUTE statement for unnamed parameters
in the prepared statement:
SQL>prepare findemp from
+>select * from persnl.employee
+>where salary > ? and jobcode = ?;
--- SQL command prepared.
SQL>execute findemp using 40000.00,450;
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
------ --------------- -------------- ------- ------- --------
232 THOMAS SPINNER 4000 450 45000.00
122 SQL Statements