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

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-160
Considerations for PREPARE
GLOBAL | LOCAL
specifies the scope of the prepared statement. The default is LOCAL. A GLOBAL
prepared statement can be executed within the SQL session. A LOCAL prepared
statement can be executed only within the module or compilation unit in which it
was prepared.
SQL-statement-variable
is a value-specification—a host variable with character data type that
specifies the SQL statement to prepare (for example, :stmt_buffer).
Considerations for PREPARE
You cannot PREPARE a compound statement.
Availability of a Prepared Statement
If a PREPARE statement fails, any subsequent attempt to execute the named
statement fails.
Only the MXCI session that executes the PREPARE can execute the associated
prepared statement. The prepared statement is available for execution until the MXCI
session terminates or until it executes another PREPARE statement that uses the
same statement name (either successfully or unsuccessfully).
A statement must be compiled by PREPARE before you can EXECUTE it, but after it is
compiled, you can EXECUTE the statement multiple times without recompiling it. In
particular, you can execute a prepared statement multiple times with different
parameter values. See MXCI Examples of EXECUTE on page 2-134.
Dynamic Parameters
A preparable statement can include any number of dynamic parameter markers (or
specifications). The syntax for a dynamic parameter marker is a question mark (?). The
data types of these markers are inferred from the context of the SQL statement.
Identifying Statements
Each SQL/MX statement embedded in a program or compiled with PREPARE has a
statement name that is an SQL identifier. If you compile a dynamic SQL statement with
PREPARE, you can specify a name for the SQL statement in the PREPARE statement.
For example:
EXEC SQL PREPARE ins_cust FROM :stmt_buffer;
where ins_cust is the name of the SQL statement.
To name a static SQL statement explicitly, precede the statement with a comment. For
more information, see C/C++ and COBOL comments in the SQL/MX Programming
Manual for C and COBOL.
C/COBOL
C/COBOL
MXCI
C/COBOL
C/COBOL