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

EXECUTE IMMEDIATE

Use the EXECUTE IMMEDIATE statement to perform the functions of the PREPARE, EXECUTE, and FREE statements.

Use this statement with ESQL/C.

Syntax

Read syntax diagramSkip visual syntax diagram                           .-;---------.
                           V           |
>>-EXECUTE IMMEDIATE--+-'----statement-+--'-+------------------><
                      '-statement_var-------'
 

Element Description Restrictions Syntax
statement A valid SQL statement See the same sections of Usage that are listed below for statement_var See this chapter.
statement_var Host variable that contains a character string of one or more SQL statements Must be a previously declared character-type variable. See EXECUTE IMMEDIATE and Restricted Statements and Restrictions on Allowed Statements. Language specific

Usage

The EXECUTE IMMEDIATE statement makes it easy to execute dynamically a single simple SQL statement that is constructed during program execution. For example, you can obtain the name of a database from program input, construct the DATABASE statement as a program variable, and then use EXECUTE IMMEDIATE to execute the statement, which opens the database.

The quoted string that includes one or more SQL statements, or the contents of statement_var, is parsed and executed if correct; then all data structures and memory resources are released immediately. In the usual method of dynamic execution, these operations require separate PREPARE, EXECUTE, and FREE statements.

The maximum length of an EXECUTE IMMEDIATE statement is 64 kilobytes.

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