execute

Description

Executes a dynamic SQL statement from a prepared statement.

For details on the execute immediate statement, see page §.

Syntax

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

NoteDo not confuse the Embedded SQL execute statement with the Embedded SQL exec statement or the Transact-SQL execute statement.

Parameters

statement_name

A unique identifier for the statement, defined in a previous prepare statement.

descriptor_name

Specifies the area of memory, or the SQLDA structure, that describes the statement’s dynamic parameter markers or select column list.

into

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.

descriptor

Identifies descriptor_name as a SQLDA structure.

sql descriptor

Identifies descriptor_name as a SQL descriptor.

using

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.

Examples

Example 1

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;

Usage

See also

declare section, get descriptor, prepare, set descriptor