EXECUTE is an executable command that can only be embedded in a host language. EXECUTE cannot be dynamically prepared.
The user must have the authority to use the previously prepared command.
EXECUTE statement-name
[USING {host-variable[,...] |
DESCRIPTOR descriptor-name} |
multiple-row-insert]
multiple-row-insert
USING {{host-variable-array | host-variable} [,...]}
| DESCRIPTOR descriptor-name}
[FOR {host-variable | integer-constant} ROWS]
statement-name | Identifies a previously prepared nonquery statement to be executed. |
host-variable | Identifies a variable described in the application program in accordance with the rules for declaring host variables in the application language. |
descriptor-name | Identifies an SQLDA containing a valid description of the host variables to be inserted into the prepared statement during execution. |
The EXECUTE command is always used in conjunction with the PREPARE statement, since the main argument for EXECUTE is a previously prepared SQL statement. The PREPARE statement tells the XDB Server about the statement to be executed, while the EXECUTE statement executes that statement, substituting host variable values where specified.
This optional keyword precedes a list of host variables whose values are substituted for the parameter markers (question marks) in the prepared statement. If the prepared statement includes parameter markers, the USING clause must be included in the EXECUTE statement.
The total number of host variables specified must equal the total number of parameter markers in the prepared statement. The order of host variables specified determines their order of substitution into the prepared statement -- with the first variable substituting for the first parameter marker in the prepared statement, etc.
This keyword indicator precedes a valid SQL Descriptor Area (SQLDA) name. The total number of host variables (as stored in SQLD) must match the total number of parameter markers in the prepared statement. The length of the SQLDA (as stored in SQLDABC) must be sufficient to accommodate all host variables. As with ordinary host variables, there is an ordered one-to-one correspondence between each host variable described in the SQLDA, and the parameter markers inside the prepared statement.
The SQLDA must have enough storage to contain all SQLVAR occurrences.
Before the prepared statement is executed, each parameter marker in the prepared statement string is essentially replaced by a corresponding host variable from the application. This replacement operation transfers the value of the host variable (source) to the corresponding parameter marker (target) within the prepared SQL statement string. The attribute of each host variable -- once transferred into its new "target position" within the SQL statement string -- depends on the original location (and role) of the replaced parameter marker.
In COBOL, host-variables are data structures defined in working storage. In the following example, we PREPARE inscust and substitute the values of the host variables c_no and company.
EXEC SQL PREPARE inscust FROM INSERT INTO customer(c_no, company) VALUES(?, ?) END-EXEC EXEC SQL EXECUTE inscust USING :CNO, :CNAME END-EXEC