MySQL string replace

后端 未结 5 2024
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 09:15

I have a column containing urls (id, url):

http://www.example.com/articles/updates/43
http://www.example.com/articles/updates/866
http://www.example.com/arti         


        
5条回答
  •  执念已碎
    2020-11-22 09:24

    You can simply use replace() function,

    with where clause-

    update tabelName set columnName=REPLACE(columnName,'from','to') where condition;
    

    without where clause-

    update tabelName set columnName=REPLACE(columnName,'from','to');
    

    Note: The above query if for update records directly in table, if you want on select query and the data should not be affected in table then can use the following query-

    select REPLACE(columnName,'from','to') as updateRecord;
    

提交回复
热议问题