Executes a dynamic SQL statement stored in a character-string host variable or quoted string.
exec sql [at connection_name] execute immediate {:host_variable | “string”};
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.
A quoted literal Transact-SQL statement string that can be used in place of host_variable.
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;
Using the execute immediate statement is dynamic SQL Method 1. See Chapter 7, “Using Dynamic SQL” for information about the four dynamic SQL methods.
Except for messages, the statement in host_variable cannot return results to the your program. Thus, the statement cannot be, for example, a select statement.
The Embedded SQL precompiler does not check the syntax of the statement stored in host_variable before sending it to Adaptive Server Enterprise. If the statement’s syntax is incorrect, Adaptive Server Enterprise returns an error code and message to your program.
Use prepare and execute (dynamic SQL method 2) to substitute values from host variables into a dynamic SQL statement.
Use prepare, open, and fetch (dynamic SQL method 3) to execute select statements with dynamic SQL statements that return results.
execute, prepare