execute immediate

Description

Executes a dynamic SQL statement stored in a character-string host variable or quoted string.

Syntax

exec sql [at connection_name] execute immediate
 {:host_variable | “string”} end-exec

Parameters

host_variable

A character-string host variable defined in a declare section. Before calling execute immediate, the host variable should contain a complete and syntactically correct Transact-SQL statement.

string

A quoted literal Transact-SQL statement string that can be used in place of host_variable.

Examples

Example 1

 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
           01     HOST-VAR    PIC X(100).
      EXEC SQL END DECLARE SECTION END-EXEC.
 
           ...
 
      DISPLAY "ENTER A NON-SELECT SQL STATEMENT: ".
      ACCEPT HOST-VAR.
 
      EXEC SQL EXECUTE IMMEDIATE :HOST-VAR END-EXEC.
 
           ...

Usage

See also

execute, prepare