Prepares and executes a dynamic SQL statement.
ANSI Compliance
EXECUTE IMMEDIATE is ANSI/ISO SQL:2011-compliant.
Required Privileges
The privileges required depend on the SQL statement and tables accessed.
Invocation
Executable.
Dynamic SQL statement.
Embedded SQL only.
Syntax
EXECUTE IMMEDIATE statement_string
Syntax Elements
- statement_string
- The text of the dynamic SQL statement as a string expression.
- statement_string_variable
- The text of the dynamic SQL statement as a host variable.
Usage Notes
Whether specified as a string expression or as a host variable, the dynamic SQL statement can be no longer than 32000 characters.
If specified as a host variable, the statement_string_variable must follow the rules for SQL strings for the client programming language, as given in the following table:
IN this language … | statement_string is a … |
---|---|
COBOL | non-numeric literal. |
C | |
PL/I | character string expression. |
If the statement string variable is VARCHAR, the statement text cannot be longer than 64K.
The dynamic SQL statement must be a single SQL statement; it cannot be a multistatement request.
Performing an EXECUTE IMMEDIATE is equivalent to performing a PREPARE followed by an EXECUTE of an unnamed dynamic single non-macro, non-data returning statement.
EXECUTE IMMEDIATE is designed to provide for this special case.
The dynamic SQL statement:
- Cannot be any of the following specific SQL statements.
- Cannot be a data returning statement.
ABORT EXECUTE IMMEDIATE BEGIN TRANSACTION FETCH CHECKPOINT LOGOFF CLOSE LOGON COMMIT OPEN CONNECT POSITION DESCRIBE PREPARE ECHO REWIND END TRANSACTION ROLLBACK EXECUTE - Cannot be a Preprocessor2 declarative.
- Cannot include host variable references.
- Requires a dynamic cursor when executed dynamically.