SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Simple and Compound Statements
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
5-11
Updating Multiple Rows
EXEC SQL END DECLARE SECTION END-EXEC.
 ...
 PROCEDURE DIVISION.
 ...
 EXEC SQL UPDATE sales.orders 
 SET deliv-date = :UPDATE-DATE
 WHERE ordernum = :UPDATE-ORDERNUM 
 FOR READ COMMITTED ACCESS 
 END-EXEC.
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. 
Examples
This example updates the SALARY column of all rows in the EMPLOYEE table where 
the SALARY value is less than the hv_min_salary host variable. A user enters the 
values for hv_inc and hv_min_salary: 
EXEC SQL UPDATE persnl.employee 
 SET salary = salary * :hv_inc 
 WHERE salary < :hv_min_salary; 
This example updates all rows in the DEPTNUM column that contain the value in HV-
OLD-DEPTNUM. After the update, all employees who were in the department specified 
by HV-OLD-DEPTNUM move to the department specified by HV-NEW-DEPTNUM. A user 
enters the values for HV-OLD-DEPTNUM and HV-NEW-DEPTNUM: 
EXEC SQL UPDATE persnl.employee
 SET deptnum = :HV-NEW-DEPTNUM 
 WHERE deptnum = :HV-OLD-DEPTNUM
END-EXEC.
Updating Columns To Null 
You can update a value in a row of data to null.
Examples
This example updates the specified SALARY column to null by using an indicator 
variable. The set_to_null host variable specifies the row to update: 
/* ind_var is set to -1 */ 
EXEC SQL UPDATE persnl.employee 
 SET salary = :emp_tbl.salary INDICATOR :ind_var 
 WHERE jobcode = :set_to_null; 
This example uses the NULL keyword instead of an indicator variable: 
EXEC SQL UPDATE persnl.employee 
 SET salary = NULL
C
COBOL
C
COBOL










