EGL Reference Guide for iSeries

delete

The EGL delete statement removes either a record from a file or a row from a database.



Syntax diagram for the delete statement

record name
Name of the I/O object: an indexed, relative, or SQL record associated with the file record or SQL row being deleted
from resultSetID
ID that ties the delete statement to a get or open statement run earlier in the same program. For details, see resultSetID.

An example is as follows:

  if (userRequest = "D")
    try
      get myRecord forUpdate;
      onException 
        myErrorHandler(12);   // exits the program
    end
 
    try
      delete myRecord;
      onException 
        myErrorHandler(16);
    end
  end

The behavior of the delete statement depends on the record type. For details on SQL processing, see SQL record.

Indexed or relative record

If you want to delete an indexed or relative record, do as follows:

After you issue the get statement, the effect of the next I/O operation on the same file is as follows:

For details on the forUpdate option, see get.

SQL record

In the case of SQL processing, you must use the forUpdate option on an EGL get or open statement to retrieve a row for subsequent deletion:

In either case, the EGL delete statement is represented in the generated code by an SQL DELETE statement that references the current row in a cursor. You cannot modify that SQL statement, which is formatted as follows:

  DELETE FROM tableName
    WHERE CURRENT OF cursor

If you wish to write your own SQL DELETE statement, use the EGL execute statement.

You cannot use a single EGL delete statement to remove rows from multiple SQL tables.


Related concepts
Record types and properties
resultSetID
Run unit
SQL support


Related tasks
Syntax diagram


Related reference
add


close
EGL statements
Exception handling
execute
get
get next
get previous
I/O error values
prepare
open
replace
SQL item properties


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