Executes a dynamic SQL statement from a prepared statement.
For details on the execute immediate statement, see “execute immediate”.
exec sql [at connection_name] execute statement_name [into {host_var_list | descriptor descriptor_name | sql descriptor descriptor_name}] [using {host_var_list | descriptor descriptor_name | sql descriptor descriptor_name}];
Do not confuse the Embedded SQL execute statement
with the Embedded SQL exec statement or the Transact-SQL execute statement.
A unique identifier for the statement, defined in a previous prepare statement.
Specifies the area of memory, or the SQLDA structure, that describes the statement’s dynamic parameter markers or select column list.
A clause required when the statement executes a select statement, which must be a single-row select. The target of the into clause can be a SQL descriptor, a SQLDA structure, or a list of one or more Embedded SQL host variables.
Each host variable in the host_var_list must first be defined in a declare section. An indicator variable can be associated with a host variable to show when a null data value is retrieved.
Identifies descriptor_name as a SQLDA structure.
Identifies descriptor_name as a SQL descriptor.
The host variables that are substituted for dynamic parameter markers in host_var_list. The host variables, which you must define in a declare section, are substituted in the order listed. Use this clause only when statement_name contains dynamic parameter markers. The dynamic descriptor can also contain the values for the dynamic parameter markers.
exec sql begin declare section;
CS_CHAR dymo_buf(128);
CS_CHAR title_id(6);
CS_INT qty;
CS_CHAR order_no(20);
exec sql end declare section;
dymo_buf = "INSERT salesdetail
(ord_num, title_id, qty) VALUES (:?, :?, :?)"
exec sql prepare ins_com from :dymo_buf;
print "Recording Book Sales";
input "Order number?", order_no;
input "Title ID?", title_id;
input "Quantity sold?", qty;
exec sql execute ins_com using :order_no, :title_id, :qty;
exec sql disconnect;
execute is the second step in method 2 of dynamic SQL. The first step is the prepare statement.
prepare and execute are valid with any SQL statement except a multirow select statement. For multirow select statements, use either dynamic cursor.
The statement in statement_name can contain dynamic parameter markers (“?”). They mark the positions where host variable values are to be substituted before the statement executes.
The execute keyword distinguishes this statement from exec. See “exec”.
declare section, get descriptor, prepare, set descriptor