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-10
Updating a Single Row
To execute an UPDATE statement, a program must have UPDATE privileges on each
column being updated in the table.
After an UPDATE statement executes, NonStop SQL/MX returns a value to the
SQLSTATE variable. If no rows were found satisfying the search condition, the value of
SQLSTATE is 02000 (no data). If a data exception occurs during the update process,
the value of SQLSTATE is 22xxx. The class value is 22, and the subclass can be a
variety of conditions, depending on the nature of the data being inserted. For
information on SQLSTATE values, see Table 13-1 on page 13-2.
Updating a Single Row
You can update a single row of data.
This example updates a single row of the ORDERS table that contains information on
the order number specified by update_ordernum:
C Searched UPDATE Example
void update_orders(void);
EXEC SQL BEGIN DECLARE SECTION;
DATE update_date;
unsigned long update_ordernum;
char SQLSTATE[6];
EXEC SQL END DECLARE SECTION;
...
int main()
{
...
... /* Input the values of update_date and update_ordernum */
update_orders();
...
return 0;
} /* end main */
void update_orders(void) {
EXEC SQL UPDATE sales.orders
SET deliv_date = :update_date
WHERE ordernum = :update_ordernum
FOR READ COMMITTED ACCESS;
} /* end update_orders */
COBOL Searched UDPATE Example
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 SQLSTATE PIC X(5).
01 UPDATE-DATE DATE.
01 UPDATE-ORDERNUM PIC 9(6) COMP.
C
COBOL