EGL Reference Guide for iSeries

execute

The EGL execute statement lets you write one or more SQL statements; in particular, SQL data-definition statements (of type CREATE TABLE, for example) and data-manipulation statements (of type INSERT or UPDATE, for example)



Syntax diagram for the execute statement

#sql{ sqlStatement }
An explicit SQL statement. If you want the SQL statement to update or delete a row in a result set, code an SQL UPDATE or DELETE statement that includes the following clause:
  WHERE CURRENT OF resultSetID

resultSetID
The resultSetID specified in the EGL open statement that made the result set available.

Leave no space between #sql and the left brace.

for SQL record name
Name of an SQL record.

If you specify a statement type (delete, insert, or update), EGL uses the SQL record to build an implicit SQL statement, as described later. In any case, you can use the SQL record to test the outcome of the operation.

preparedStatementID
Refers to an EGL prepare statement that has the specified ID. If you do not reference a prepare statement, you must specify either an explicit SQL statement or a combination of an SQL record and a statement type (delete, insert, or update).
delete, insert, update
Indicates that EGL is to provide an implicit SQL statement of the specified type. A declaration-time error occurs if you specify a statement type but not an SQL record name.

If you do not set a statement type, you must specify either an explicit SQL statement or a reference to a prepare statement.

For an overview of implicit SQL statements, see SQL support.

Several example statements are as follows (assuming that employeeRecord is an SQL record):

  execute 
    #sql{ 
      create table employee (
			 	   empnum decimal(6,0) not null,
 				   empname char(40) not null,
				   empphone char(10) not null)
    };
 
  execute update for employeeRecord;
 
  execute
    #sql{ 
      call aStoredProcedure( :argumentItem)
    };

You can use an execute statement to issue SQL statements of the following types:

You cannot use an execute statement to issue SQL statements of the following types:

Implicit SQL DELETE

The effect of requesting an implicit SQL DELETE statement is that an SQL record property (defaultSelectCondition) determines what table rows are deleted, so long as the value in each SQL table key column is equal to the value in the corresponding key item of the SQL record. If you specify neither a record key nor a default selection condition, all table rows are deleted.

The implicit SQL DELETE statement for a particular record is similar to the following statement:

  DELETE FROM tableName
  WHERE  keyColumn01 = :keyItem01

You cannot use a single EGL statement to delete rows from more than one database table.

Implicit SQL INSERT

The effect of requesting an implicit SQL INSERT statement is as follows by default:

The format of the implicit SQL INSERT statement is like this:

  INSERT INTO tableName
    (column01, ... columnNN)
    values (:recordItem01, ... :recordItemNN)

Some error conditions are as follows:

Implicit SQL UPDATE

The effect of requesting an implicit SQL UPDATE statement is as follows by default:

The format of the implicit SQL UPDATE statement for a particular record is similar to the following statement:

  UPDATE tableName
  SET    column01 = :recordItem01column02 = :recordItem01, ... 
         columnNN = :recordItemNN
  WHERE  keyColumn01 = :keyItem01

An error occurs in any of the following cases:


Related concepts
Record types and properties
SQL support
References to parts


Related tasks
Syntax diagram


Related reference
add
close
delete
EGL statements
Exception handling
get
get next
get previous
I/O error values
open
prepare
replace
SQL item properties
sysVar.terminalID


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]