Icon EXECUTE

Executes a previously-prepared SQL statement.

Syntax
EXECUTE <StatementName> [USING <Value> [,<Value>]]

Usage
Use this statement to execute a previously-prepared DDL, DML, or administrative SQL statement. SQL statements are prepared using the PREPARE statement. If the prepared 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.

After executing an SQL statement, you can use the ROWSAFFECTED function to determine the number of rows affected by the statement.

Examples
-- This procedure creates 100,000 test
-- rows in the Customers table using a
-- parameterized INSERT statement

CREATE PROCEDURE PopulateCustomers()
BEGIN
   DECLARE stmt STATEMENT;
   DECLARE I INTEGER DEFAULT 1;

   PREPARE stmt FROM 'INSERT INTO Customers
                      (CustNo, Name)
                      VALUES (?, ?)';

   WHILE I <= 10000 DO
      EXECUTE stmt USING I, 'Test Customer #' + CAST(I AS VARCHAR(10));
      SET I = I + 1;
   END WHILE;

   UNPREPARE stmt;
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