遇到一个小需求,要修改字段中部分值。mysql中的replace可以实现。
mysql> select * from syk_test; +-----------+-----------+ | user | host | +-----------+-----------+ | repluser | % | | syk | % | | mysql.sys | localhost | | root | localhost | +-----------+-----------+ 4 rows in set (0.00 sec) mysql> update syk_test set host = replace (host,‘local‘,‘my‘); Query OK, 2 rows affected (0.00 sec) Rows matched: 4 Changed: 2 Warnings: 0 mysql> select * from syk_test; +-----------+--------+ | user | host | +-----------+--------+ | repluser | % | | syk | % | | mysql.sys | myhost | | root | myhost | +-----------+--------+ 4 rows in set (0.00 sec)
replace(object, search,replace)把object中出现search的全部替换为replace
本文出自 “刚刚出壳的小鸟” 博客,请务必保留此出处http://qhd2004.blog.51cto.com/629417/1931021
原文地址:http://qhd2004.blog.51cto.com/629417/1931021