EXECUTE IMMEDIATE statement [SP]
518
EXECUTE IMMEDIATE statement [SP]
Use this statement 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.
$ For more information about using the EXECUTE IMMEDIATE
statement in procedures, see "Using the EXECUTE IMMEDIATE statement
in procedures" on page 483 of the book ASA User’s Guide.
"CREATE PROCEDURE statement" on page 453
"BEGIN statement" on page 404
"EXECUTE statement" on page 514
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.
The EXECUTE IMMEDIATE statement does not support statements and
queries that return result sets.
Only global variables can be referenced in a statement executed by
EXECUTE IMMEDIATE.
Only syntax 2 can be used in Transact-SQL stored procedures and triggers.
♦
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
Function
Syntax 1
Syntax 2
Permissions
Side effects
See also
Description
Standards and
compatibility
Example