MySQL string replace

后端 未结 5 2060
没有蜡笔的小新
没有蜡笔的小新 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:25

    Yes, MySQL has a REPLACE() function:

    mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
        -> 'WwWwWw.mysql.com'
    

    http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

    Note that it's easier if you make that an alias when using SELECT

    SELECT REPLACE(string_column, 'search', 'replace') as url....
    

提交回复
热议问题