+2 votes
in Databases by (40.7k 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

+1 vote
by (157k points)
edited by

Try the following:

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

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

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


...