+2 votes
in Databases by (15.3k points)
I want to update the value of a column by replacing some part of its value to some other values. How can I replace the substring?

E.g. The current value of the column is 'Hello abc, how are you' and I want new value 'Hello xyz, how are you'.

1 Answer

0 votes
by (27.1k points)

Try the following:

update TABLENAME set COLUMN = REPLACE(COLUMN, current substring, new substring) 

E.g. The following SQL will replace the substring 'https://m.example.com' to 'https://example.com/m' in column link_content of table me_links.

update me_links set `link_content` = REPLACE(link_content, 'https://m.example.com','https://example.com/m')