Deleting A Single Row; Deleting Multiple Rows - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Data Retrieval and Modification
To run a DELETE statement, a process started by the program must have read and
write access to the table or view and to tables or views specified in subqueries of the
search condition. For details, see
NonStop SQL/MP returns these values to sqlcode after a DELETE statement.
sqlcode
Value
0
100
<0
>0 (¦100)
After a successful DELETE operation, the SQLCA structure contains the number of
rows deleted. If an error occurs, the SQLCA contains the approximate number of rows
deleted. To return the contents of the SQLCA, use SQLCA_DISPLAY2_ or
SQLCA_TOBUFFER2_ procedure. For more information, see
System Procedures

Deleting a Single Row

To delete a single row, move a key value to a host variable and then specify the host
variable in the WHERE clause. This example deletes only one row of the EMPLOYEE
table because each value in empnum (the primary key) is unique. A user enters the
value for the host variable hostvar_empnum.
EXEC SQL DELETE FROM persnl.employee
WHERE empnum = :hostvar_empnum;

Deleting Multiple Rows

If you do not need to check a column value before you delete a row, use a single
DELETE statement to delete multiple rows in a table. This example deletes all rows (or
employees) from the EMPLOYEE table specified by delete_deptnum (which is
entered by a user).
EXEC SQL DELETE FROM persnl.employee
WHERE deptnum = :delete_deptnum ;
This example deletes all suppliers from the PARTSUPP table who charge more than
terminal_max_cost for a terminal. Terminal part numbers range from
term_first_num to term_last_num.
EXEC SQL DELETE FROM invent.partsupp
WHERE partnum BETWEEN :term_first_num AND :term_last_num
AND partcost > :terminal_max_cost ;
HP NonStop SQL/MP Programming Manual for C—429847-008
Required Access Authority
Description
The DELETE statement was successful.
No rows were found on a search condition.
An error occurred;
A warning occurred;
and
Section 9, Error and Status
4-13
sqlcode
contains the error number.
sqlcode
contains the first warning number.
Reporting.
Deleting a Single Row
on page 7-1.
Section 5, SQL/MP

Advertisement

Table of Contents
loading

Table of Contents