execute

Description

Executes a dynamic SQL statement from a prepared statement.

See execute immediate.

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}] end-exec

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

An into clause is 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 END-EXEC.
        01     DEMO-BUF   PIC X(100).
        01     TITLE-ID   PIC X(6).
        01     ORDER-NO   PIC X(20).
        01     QTY        PIC S9(9).
   EXEC SQL END DECLARE SECTION END-EXEC.
 
           ...
 
   MOVE "INSERT salesdetail(ord_num, title_id, qty) VALUES( :?, :?, :?)"
 -                 TO DEMO-BUF.
   EXEC SQL PREPARE ins_stmt FROM :DEMO-BUF END-EXEC.

   DISPLAY "RECORDING BOOK SALES".
   DISPLAY "ORDER # ? ".
   ACCEPT ORDER-NO.
   DISPLAY "TITLE ID? ".
   ACCEPT TITLE-ID.
   DISPLAY "QTY SOLD? ".
   ACCEPT QTY.
 
   EXEC SQL EXECUTE ins_stmt USING :ORDER-NO, :TITLE-ID, :QTY END-EXEC.
 
           ...

Usage

See also

declare section, get descriptor, prepare, set descriptor