Neoview SQL Reference Manual (R2.4 SP2)
PREPARE Statement
• “Syntax Description of PREPARE”
• “Considerations for PREPARE”
• “Examples of PREPARE”
The PREPARE statement compiles an SQL statement for later use with the EXECUTE statement
in a Neoview Command Interface (NCI) session.
You can also use PREPARE to check the syntax of a statement without executing the statement
in a Neoview Command Interface (NCI) session.
PREPARE statement-name FROM statement
Syntax Description of PREPARE
statement-name
is an SQL identifier that specifies a name to be used for the prepared statement. See
“Identifiers” (page 257). The statement name should be a character string and not a numeric
value. If you specify the name of an existing prepared statement, the new statement overwrites
the previous one.
statement
specifies the SQL statement to prepare.
Considerations for PREPARE
Availability of a Prepared Statement
If a PREPARE statement fails, any subsequent attempt to run EXECUTE on the named statement
fails.
Only the Neoview Command Interface session that executes the PREPARE can run EXECUTE
on the prepared statement. The prepared statement is available for running EXECUTE until you
terminate the Neoview Command Interface session.
A statement must be compiled by PREPARE before you can run EXECUTE on it. However, after
the statement is compiled, you can run EXECUTE on the statement multiple times without
recompiling the statement.
Examples of PREPARE
• Prepare a SELECT statement, checking for syntax errors:
SQL>prepare empsal from
+>select salary from employee
+>where jobcode = 100;
*** ERROR[4082] Table, view or stored procedure NEO.INVENT.EMPLOYEE does not exist or is inaccessible.
*** ERROR[8822] The statement was not prepared.
SQL>
• Prepare a SELECT statement with an unnamed parameter (?) and later run EXECUTE on
it:
SQL>prepare findsal from
+>select salary from persnl.employee
+>where jobcode = ?;
--- SQL command prepared.
SQL>execute findsal using 450;
SALARY
----------
PREPARE Statement 153