Direct deletions
You can embed a DELETE statement in a program. The following
example uses :
EXEC SQL delete from items
WHERE order_num = :onum;
You can also prepare and execute a statement of the same form dynamically. In either case, the statement works directly on the database to affect one or more rows.
The WHERE clause in the example uses the value of a host variable named onum. Following the operation, results are posted in SQLSTATE and in the sqlca structure, as usual. The third element of the SQLERRD array contains the count of rows deleted even if an error occurs. The value in SQLCODE shows the overall success of the operation. If the value is not negative, no errors occurred and the third element of SQLERRD is the count of all rows that satisfied the WHERE clause and were deleted.