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”}; 

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;
     CS_CHAR         host_var(128);
 exec sql end declare section;  
 
 printf(“Enter a non-select SQL statement: “);
 gets(host_var);
 
 exec sql execute immediate :host_var;

Usage

See also

execute, prepare