Prepares and runs a statement in a stored procedure.
ANSI Compliance
ANSI/ISO SQL:2011-compliant.
Required Privileges
None.
Invocation
Executable.
Stored procedures only.
Syntax
EXECUTE IMMEDIATE statement_name
Syntax Elements
- statement_name
- One of the following:
- A literal
- A reference to an SQL string variable
- A parameter
Example: Using EXECUTE IMMEDIATE
CREATE PROCEDURE sales_update(store_table VARCHAR(10),
item INTEGER,
price DECIMAL(8,2) )
BEGIN
DECLARE sql_stmt VARCHAR(100);
SET
SET sql_stmt = 'UPDATE ' || store_table || ' SET store_price=' || price ||
' WHERE store_item =' || item;
EXECUTE IMMEDIATE sql_stmt;
END;