The UPDATE statement updates the values of specified columns in rows of a table.
Invocation
This statement can be used in an application program using the DB2 CLI functions or issued through the CLP.
Syntax
>>-UPDATE--table-name--SET--------------------------------------> .-,----------------------------------. V | >----+--------------------------------+-+-----------------------> '-column-name--=----expression---' >--+---------------------------------+------------------------->< '-WHERE----| search_condition |---' expression: .-arithmetic operator---------. V | |----+---+--+-literal----------+-+------------------------------| +-+-+ +-column-name------+ '---' '-special register-' operator: |--+-CONCAT-+---------------------------------------------------| +-/------+ +-*------+ +-+------+ '--------' search_condition: .----------------------------------------------. V | |----+------------------------------------------+-+-------------| '-+-AND-+--+-----+--+-| predicate |------+-' '-OR--' '-NOT-' '-(search_condition)-' predicate: (1) |--+-| basic predicate |-+--------------------------------------| +-| IN predicate |----+ +-| LIKE predicate |--+ '-| NULL predicate |--' basic predicate: |--| expression |--+-=--+--| expression |-----------------------| +-<>-+ +-<--+ +->--+ +-<=-+ +->=-+ '-||-' IN predicate: |--| expression |--+-----+--IN--(--| expression |--)------------| '-NOT-' LIKE predicate: |--| expression |--+-----+--LIKE--| expression |----------------| '-NOT-' NULL predicate: |--| expression |--IS--+-----+--NULL----------------------------| '-NOT-' relational operator: |--+-=-----------+----------------------------------------------| +-<>----------+ +-<-----------+ +->-----------+ +-<=----------+ +->=----------+ +-LIKE--------+ +-NOT LIKE----+ +-IS NULL-----+ '-IS NOT NULL-'
Poznámky:
Description
Arithmetic operations on BLOB(n), DATE, TIME, and TIMESTAMP data types are not supported.
The result of a search_condition is derived by applying the specified logical operators (AND, OR, NOT) to the result of each specified predicate. A predicate compares two values. If logical operators are not specified, the result of the search condition is the result of the specified predicate.
Search conditions within parentheses are evaluated first. If the order of evaluation is not specified by parentheses, NOT is applied before AND, and AND is applied before OR. The order in which operators at the same precedence level are evaluated is undefined to allow for optimization of search conditions.
The search_condition is applied to each row of the table and the updated rows are those for which the result of the search_condition is true.
Each column-name in the search condition must identify a column of the table.
You can use the CONCAT, MOD, LENGTH, and RTRIM functions in the predicate expression of the search condition. For more information about the MOD function, see page ***.
Rules
Example
Change the phone number (PHONENO) of employee number (EMPNO) '003002' in the EMPLOYEE table to '1234'.
UPDATE EMPLOYEE SET PHONENO = '1234' WHERE EMPNO = '003002'
Související odkazy