在MySQL中用正则表达式替换数据库中的内容的方法
给自己一点时间接受自己,爱自己,趁着下午茶的时间来学习图老师推荐的在MySQL中用正则表达式替换数据库中的内容的方法,过去的都会过去,迎接崭新的开始,释放更美好的自己。
将comment表中的author_url包含www.sohu.com的记录,其中的sohu替换为sina,一个语句搞定~
update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';
带IF判断的复杂替换
update comment set url=IF(url REGEXP 'test.yahoo.com.cn',REPLACE(url,'www1.sohu.com','www.sina.com'),REPLACE(url,'www2.yahoo.com','www.sina.com')) where 1=1;


