您的位置:首页 > 数据库 > MySQL

mysql的replace函数替换字符串

2009-01-13 13:51 323 查看
replace 函数即可批量改变某字段中的某一段字符串。

查 mysql 里的 replace 函数
update `xxx` set `a` = replace(`a` , '要替换的' , '替换为的') where xxx
===PHPCHINA.COM===============================================================

update `xxx` set `a` = replace(`a` , '要替换的' , '替换为的') where xxx
update `music` set `file` = replace(`file` , '' , 'ddd') where id<10

UPDATE music SET file=REPLACE(file, '', 'def') where id < 10 ;

===mysql.com===============================================================
用mysql的replace函数替换字符串
比如你要将 表 tb1里面的 f1字段的abc替换为def

UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');

REPLACE(str,from_str,to_str)
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串:
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
这个函数是多字节安全的。
==================================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: