EXECUTE IMMEDIATE and Restricted Statements

The EXECUTE IMMEDIATE statement cannot execute the following SQL statements.
  • CLOSE
  • CONNECT
  • DECLARE
  • DISCONNECT
  • EXECUTE
  • EXECUTE FUNCTION
  • EXECUTE PROCEDURE
  • FETCH
  • FLUSH
  • FREE
  • GET DESCRIPTOR
  • GET DIAGNOSTICS
  • OPEN
  • OUTPUT
  • PREPARE
  • PUT
  • SELECT
  • SET AUTOFREE
  • SET CONNECTION
  • SET DEFERRED_PREPARE
  • SET DESCRIPTOR
  • WHENEVER
For EXECUTE PROCEDURE, this restriction applies only to calls that return one or more values.

The only form of the SELECT statement that EXECUTE IMMEDIATE supports as statement text is SELECT ... INTO TEMP table. For the syntax of the INTO TEMP table clause in SELECT statements, see INTO table clauses.

In addition, ESQL/C cannot use the EXECUTE IMMEDIATE statement to execute the following statements in text that contains multiple SQL statements that are separated by semicolons:
  • CLOSE DATABASE
  • CREATE DATABASE
  • DATABASE
  • DROP DATABASE
  • SELECT (except SELECT INTO TEMP)
The EXECUTE IMMEDIATE statement cannot process SQL statement text that includes question mark ( ? ) symbols as placeholders. Use the PREPARE statement and either a cursor or the EXECUTE statement to execute a dynamically constructed SELECT statement.

(In SPL routines, the EXECUTE IMMEDIATE statement can execute only a single SQL statement. If the specification that immediately follows the IMMEDIATE keyword evaluates to a list of multiple SQL statements, or by a NULL value, or text that is not a valid SQL statement, the database server issues a runtime error.)