Adaptive Server IQ Reference Manual
|Chapter 9 SQL Statements|
|EXECUTE IMMEDIATE statement [ESQL] [SP]|
To enable dynamically constructed statements to be executed from within a procedure.
EXECUTE IMMEDIATE string-expression
EXECUTE ( string-expression )
The following procedure creates a table, where the table name is supplied as a parameter to the procedure. The EXECUTE IMMEDIATE statement must all be on a single line.
CREATE PROCEDURE CreateTableProc( IN tablename char(30) ) BEGIN EXECUTE IMMEDIATE 'CREATE TABLE ' || tablename || ' ( column1 INT PRIMARY KEY)' END
To call the procedure and create a table mytable:
CALL CreateTableProc( 'mytable' )
The EXECUTE IMMEDIATE statement extends the range of statements that can be executed from within procedures. It allows dynamically prepared statements to be executed, such as statements that are constructed using the parameters passed in to a procedure.
Literal strings in the statement must be enclosed in single quotes, and must differ from any existing statement name in a PREPARE or EXECUTE IMMEDIATE statement. The statement must be on a single line.Side effects
None. However, if the statement is a data definition statement with an automatic commit as a side effect, then that commit does take place.
Intermediate level feature.
Supported in Open Client/Open Server.
None. The statement is executed with the permissions of the owner of the procedure, not with the permissions of the user who calls the procedure.