Updating Multiple Rows; Updating Columns With Null Values; Delete Statement - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Data Retrieval and Modification
If the UPDATE operation fails, check for SQL error 8227, which indicates you
attempted to update a row with an existing key (primary or unique alternate).

Updating Multiple Rows

If you do not need to check a value in a row before you update the row, use a single
UPDATE statement to update multiple rows in a table.
This example updates the SALARY column of all rows in the EMPLOYEE table where
the SALARY value is less than hostvar_min_salary. A user enters the values for
hostvar_inc and hostvar_min_salary.
EXEC SQL
UPDATE persnl.employee
SET salary = salary * :hostvar_inc
WHERE salary < :hostvar_min_salary;
This example updates all rows in the EMPLOYEE.DEPTNUM column that contain the
value in hostvar_old_deptnum. After the update, all employees who were in the
department specified by hostvar_old_deptnum moved to the department specified
by hostvar_new_deptnum. A user enters the values for hostvar_old_deptnum
and hostvar_new_deptnum.
EXEC SQL UPDATE persnl.employee
SET deptnum = :hostvar_new_deptnum
WHERE deptnum = :hostvar_old_deptnum;

Updating Columns With Null Values

This example updates the specified SALARY column to a null value using an indicator
variable. The set_to_nulls host variable specifies the row to update.
/* indicator-var is set to -1 */
EXEC SQL UPDATE persnl.employee
SET SALARY = :emp_tbl.salary
INDICATOR :indicator_var
WHERE :emp_tbl.jobcode = set_to_nulls;
This example uses the NULL keyword instead of an indicator variable:
EXEC SQL UPDATE persnl.employee SET SALARY = NULL
WHERE :emp_tbl.jobcode = set_to_nulls;

DELETE Statement

The DELETE statement deletes one or more rows from a table or protection view. If
you delete all rows from a table, the table still exists until it is deleted from the catalog
by a DROP TABLE statement. (To delete a set of rows, one row at a time using a
cursor, see
Using SQL Cursors
HP NonStop SQL/MP Programming Manual for C—429847-008
on page 4-14.)
4-12
Updating Multiple Rows

Advertisement

Table of Contents
loading

Table of Contents