EXECUTE IMMEDIATE Statement [ESQL] [SP]

Extends the range of statements that can be executed from within procedures. It lets you execute dynamically prepared statements, such as statements that are constructed using the parameters passed in to a procedure.

Quick Links:

Go to Parameters

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

Syntax 1

EXECUTE IMMEDIATEexecute-option ] string-expression

execute-option:
   WITH QUOTESON | OFF ]
   | WITH ESCAPESON | OFF } 
   | WITH RESULT SETON | OFF }

Syntax 2

EXECUTEstring-expression )

Parameters

(back to top)

Examples

(back to top)

Usage

(back to top)

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.

Only global variables can be referenced in a statement executed by EXECUTE IMMEDIATE.

Only syntax 2 can be used inside Transact-SQL stored procedures.

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.

Standards

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Sybase Database product—Supported in Open Client/Open Server.

Permissions

(back to top)

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.

Related reference
BEGIN … END Statement
CREATE PROCEDURE Statement
QUOTED_IDENTIFIER Option [TSQL]