Reference Manual
CHAPTER 9. SQL Statements
To enable dynamically constructed statements to be executed from within a procedure.
EXECUTE IMMEDIATE string-expression
EXECUTE ( string-expression )
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.
None. However, if the statement is a data definition statement with an automatic commit as a side effect, that commit does take place.
The EXECUTE IMMEDIATE statement extends the range of statements that can be executed from within procedures and triggers. It lets you execute dynamically prepared statements, 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 the statement must be on a single line.
SQL/92 Intermediate level feature.
Sybase Supported in Open Client/Open Server.
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' )