Icon EXECUTE IMMEDIATE

Executes an SQL statement.

Syntax
EXECUTE IMMEDIATE <SQLStatement>
[USING <Value> [,<Value>]]

Usage
Use this statement to execute the specified DDL, DML, or administrative SQL statement. If the SQL statement is parameterized, then you can use the USING clause to specify the values to use for the parameters. The values are in left-to-right order, corresponding to how the parameters were declared in the SQL statement.

Examples
-- This procedure executes a
-- CREATE TABLE statement to create a
-- temporary table

CREATE PROCEDURE CreateTestTable()
BEGIN
   EXECUTE IMMEDIATE 'CREATE TEMPORARY TABLE "TestTable"
                     (
                     "FirstColumn" INTEGER,
                     "SecondColumn" VARCHAR(30),
                     "ThirdColumn" CLOB,
                     PRIMARY KEY ("FirstColumn")
                     )

                     DESCRIPTION ''Test Table''';
END

-- This function returns the user-defined
-- version for a given table, or NULL if
-- the table does not exist

FUNCTION "GetTableVersion" (IN TableName VARCHAR)
RETURNS DECIMAL(19,2)
BEGIN
   DECLARE Version DECIMAL(19,2) DEFAULT 0;
   EXECUTE IMMEDIATE 'SELECT Version INTO ?
        FROM Information.Tables WHERE Name=?'
        USING Version,TableName;
   RETURN Version;
END

SQL 2003 Standard Deviations
This statement deviates from the SQL 2003 standard in the following ways:

DeviationDetails
Dynamic SQLThe use of dynamic SQL for DDL, DML, and administrative statement execution instead of static SQL in procedures and functions is both an ElevateDB extension and a deviation from the standard.
Image