![]() |
|
Use the EXECUTE IMMEDIATE statement to perform the functions of the PREPARE, EXECUTE, and FREE statements.
Use this statement with ESQL/C.
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 is a character string that includes one or more SQL statements. The string, 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 functions are distributed among the PREPARE, EXECUTE, and FREE statements.
The maximum length of an EXECUTE IMMEDIATE statement is 64 kilobytes.
You cannot use the EXECUTE IMMEDIATE statement to execute the following SQL statements. Although the EXECUTE PROCEDURE statement appears on this list, the restriction applies only to EXECUTE PROCEDURE statements that return values.
In addition, you cannot use the EXECUTE IMMEDIATE statement to execute the following statements in text that contains multiple statements that are separated by semicolons.
Use a PREPARE and either a cursor or the EXECUTE statement to execute a dynamically constructed SELECT statement.
The following restrictions apply to the statement that is contained in the quoted string or in the statement variable:
The following examples show EXECUTE IMMEDIATE statements in ESQL/C. Both examples use host variables that contain a CREATE DATABASE statement. The first example uses the SQL statement terminator (;) inside the quoted string.
Related statements: EXECUTE, FREE, and PREPARE
For a discussion of quick execution, see the Informix Guide to SQL: Tutorial.