Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

PREPARE

Use the PREPARE statement to parse, validate, and generate an execution plan for one or more SQL statements at runtime.

Use this statement with ESQL/C.

Syntax

Read syntax diagramSkip visual syntax diagram>>-PREPARE--+-statement_id-----+--FROM-------------------------->
            '-statement_id_var-'
 
>--+-' statement_text '-+--------------------------------------><
   '-statement_var------'
 
Element Description Restrictions Syntax
statement_id Identifier declared here for the prepared object Must be unique in the database among names of cursors and prepared objects Identifier
statement_id_var Host variable storing statement_id Must have been previously declared as a character data type Language specific
statement_text Text of the SQL statement(s) to prepare See Preparing Multiple SQL Statements and Statement Text. Quoted String.
statement_var Host variable storing the text of one or more SQL statements Must be a character data type. Not valid if the SQL statement(s) contains the Collection-Derived-Table segment. Language specific

Usage

The PREPARE statement enables your program to assemble the text of one or more SQL statements at runtime (creating a prepared object) and make it executable. This dynamic form of SQL is accomplished in three steps:

  1. A PREPARE statement accepts statement text as input, either as a quoted string or stored within a character variable. Statement text can contain question-mark ( ? ) placeholders to represent values that are to be defined when the statement is executed.
  2. An EXECUTE or OPEN statement can supply the required input values and execute the prepared statement once or many times.
  3. Resources allocated to the prepared statement can be released later using the FREE statement.

In Dynamic Server, the same collating order that is current when you create a prepared object is also used when that object is executed, even if the execution-time collation of the session (or of DB_LOCALE) is different.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]