IMMEDIATE is used in the EXECUTE IMMEDIATE statement to run dynamic SQL. Instead of compiling a statement ahead of time with PREPARE, the database parses, optimizes, and executes the supplied character string on the spot. This allows you to build SQL at runtime, substitute bind variables, and run DDL, DML, or PL/SQL blocks that cannot be parameterized through ordinary prepared statements. While powerful, EXECUTE IMMEDIATE bypasses some compile-time checks, so errors surface only when the string is executed. It should therefore be combined with bind variables and rigorous validation to limit SQL injection risks. In transactional contexts the executed statement behaves like any other SQL command: it can be committed, rolled back, and it respects the current isolation level.
string_expression
(STRING) - The SQL text to execute at runtime.variable_list
(Variable(s)) - Optional target variables for SELECT results (Oracle).bind_arg
(ANY) - Values substituted into positional or named placeholders inside the string.PREPARE, EXECUTE, dynamic SQL, bind variables, sp_executesql, PREPARE/EXECUTE in MySQL, PL/pgSQL EXECUTE
SQL/92 dynamic SQL feature; popularised in Oracle 8i
PREPARE creates a reusable execution plan that can be run many times, while EXECUTE IMMEDIATE parses and runs the string once in a single step.
Yes. Most dialects let you specify USING clauses so values are bound safely and efficiently.
The dynamic string probably has a syntax error or is missing required privileges. Print the string, run it manually, and verify syntax.
No. It follows the surrounding transaction rules. You control commits and rollbacks explicitly.