Marks the beginning of a SQL statement embedded in a host language program.
exec sql [at connection_name] sql_statement;
Causes the SQL statement sql_statement to execute at the Adaptive Server connection connection_name.
The connection name that identifies the Adaptive Server connection where sql_statement is to execute. The connection_name must be defined as a previous connect statement.
A Transact-SQL statement or other Embedded SQL statement.
exec sql
begin declare section;
char site1(20);
int sales1;
exec sql end declare section;
exec sql connect “user1” identified by “password1”
using “server1”;
exec sql connect “user2” identified by “password2”
using “server2”
/* Remember that a connection that has not been
explicitly named has the name of its server */
exec sql at server1 select count(*) from sales
into :sales1;
site1 = sitename(“server1”);
exec sql at server2 insert into numsales
values(:site1, :sales1);
SQL statements embedded in a host language must begin with exec sql. The keywords exec sql can appear anywhere that a host language statement can begin.
The statement sql_statement can occupy one or more program lines; however, it must conform to host language rules for line breaks and continuation lines.
The at clause affects only the statement sql_statement. The clause does not affect subsequent SQL statements, and does not reset the current connection.
The at clause is not valid when sql_statement is one of the following SQL statements:
allocate descriptor |
begin declare section |
connect |
deallocate descriptor |
declare cursor (dynamic) |
end declare section |
exit |
get diagnostics |
include file |
include sqlca |
set connection |
set diagnostics |
whenever |
connection_name must be defined in a previous connect statement.
Each Embedded SQL statement must end with a terminator. In C, the terminator is the semicolon (;).
begin declare section, connect, disconnect, set connection