Erases records from a relation. Before using the ERASE statement,
you must start a read/write transaction and establish a record
stream using a context variable with a FOR statement or a START_
STREAM statement. You cannot erase records from a view that was
formed with a WITH, REDUCED, or CROSS clause of an RDO record
selection expression. Also, you cannot erase records from a view
that was formed with a UNION clause of an SQL select expression.
Example:
RDO> START_TRANSACTION READ_WRITE RESERVING
cont> COLLEGES FOR EXCLUSIVE WRITE
RDO> FOR C IN COLLEGES
cont> ERASE C
cont> END_FOR
RDO> COMMIT
1 – Format
(B)0[m[4mERASE[m q> context-var qwqqqqqqq>qqqqqwq>
mq> on-error qj
1.1 – context-var
A temporary name specified in an RSE for name recognition. You
must define the context variable in a START_STREAM statement or
in a FOR loop. Request HELP on RSE for more information.
1.2 – on-error
The ON ERROR clause, which specifies a host language statement or
Oracle Rdb data manipulation statement to be performed if an Oracle Rdb
error occurs. Request HELP on ON_ERROR for more information.
2 – More
You need the Oracle Rdb READ and ERASE privileges to the relation
and the Oracle Rdb ERASE privilege to the database to use the ERASE
statement.
You cannot erase records from a view that was formed with one of
the following clauses:
o WITH clause of an RDO record selection expression
o REDUCED TO clause of an RDO record selection expression
o CROSS clause of an RDO record selection expression
o UNION clause of an SQL select expression
Prior to Version 4.1, Oracle Rdb allowed you to erase rows from a
table that was directly joined with other tables. Beginning with
Version 4.1, Oracle Rdb returns an error message if you try to erase
a row under these conditions. For example, Oracle Rdb will return
the error, $RDMS-E-JOIN_CTX_UPD, relation EMPLOYEES is part of
a join, cannot be updated, when you try to execute the following
query:
FOR E IN EMPLOYEES CROSS D IN DEGREES OVER EMPLOYEE_ID
WITH D.DEGREE= 'MA'
ERASE E
END_FOR
In the preceding query, if an employee has two MA degrees, the
same employee row will be joined to two different degree rows.
Therefore, Oracle Rdb will try to delete the same row twice. The
previous update query can be reworded into an equivalent form to
achieve the desired results as follows:
FOR E IN EMPLOYEES WITH
(ANY D IN DEGREES WITH D.EMPLOYEE_ID = E.EMPLOYEE_ID)
ERASE E
END_FOR
The rows can now be erased because the EMPLOYEES table is no
longer directly joined to the DEGREES table. The use of this
query guarantees that an employee row will not be deleted more
than once.
Note that some examples in the Guide to Using RDO, RDBPRE, and
RDML will no longer work with the update rules created in Oracle Rdb
Version 4.1. To run these examples, rewrite them using the ANY
subquery mentioned previously.
3 – Examples
Example 1
Assume you wish to erase all the records in the COLLEGES
relation:
RDO> START_TRANSACTION READ_WRITE RESERVING
cont> COLLEGES FOR EXCLUSIVE WRITE
RDO> FOR C IN COLLEGES ERASE C END-FOR
RDO> PRINT COUNT OF C IN COLLEGES
0
RDO> COMMIT
This statement uses the loop established by the FOR statement and
erases all the records from the COLLEGES relation.