PREPARE
- Last Updated: December 12, 2014
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
Parses and assigns a name to an ad hoc or dynamically generated
SQL statement for execution. You use a PREPARE statement
in a series of steps that allows a program to accept or generate
SQL statements at run time.
Syntax
|
Parameters
- statement_name
-
A name for the dynamically generated statement.
DESCRIBE,EXECUTE, andDECLARE CURSORstatements refer to this statement_name. A statement_name must be unique in a program. - statement_string
-
Specifies the SQL statement to be prepared for dynamic execution. You can use either the name of a C Language string variable containing the SQL statement, or you can specify the SQL statement as a quoted literal. If there is an SQL syntax error, the
PREPAREstatement returns an error in theSQLCA.{ :host_variable | quoted_literal }
Notes
- A
statement string can have one or more references to input variables.
These variables represent values supplied at run time to:
INSERTandUPDATEstatements- Predicates in
DELETE,UPDATE, andSELECTstatements
- A program supplies an input variable to a
PREPAREstatement either as a substitution name or as a parameter marker. For example:- A substitution name is a name preceded by a colon (
:) in a statement string. This name does not refer to a C Language variable, but acts only as a placeholder for input variables. - A parameter marker is a question mark (
?) in the statement string, serving as a placeholder for input variables.
- A substitution name is a name preceded by a colon (
- The
USINGclauses ofEXECUTEandOPENstatements identify host language storage. The values in this storage expand a statement string, replacing a substitution name or a parameter marker. You can design your program to execute the same prepared statement many times in a transaction, supplying different values for input variables for each execution. If youCOMMITorROLLBACKthe transaction, you mustPREPAREthe statement string again.
Example
The
first example is a code fragment from the DynUpd function
in sample program 3DynUpd.pc, which illustrates
dynamic processing of an UPDATE statement:
|
This example is a code fragment from the DynSel function
in sample program 4DynSel.pc, which illustrates
dynamic processing of a SELECT statement:
|