Wednesday, February 12, 2014

DB2 Update Replace String with another String

In DB2, REPLACE function allows to replace a string with another string. This can be used in update statement as below:

Suppose you want to replace text "India" with "USA" in COLLDESC.MARKETINGTEXT column,
below statement should do it.


UPDATE COLLDESC SET MARKETINGTEXT = (select REPLACE(MARKETINGTEXT,'India,'USA') from COLLDESC WHERE COLLATERAL_ID=123) WHERE COLLATERAL_ID=123;