mySQL中replace的用法

来源:互联网 发布:egd网络黄金 编辑:程序博客网 时间:2024/05/15 12:22
mysql replace实例说明:

UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
REPLACE(str,from_str,to_str)
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串

这个函数用来批量替换数据中的非法关键字是很有用的!如下例子:

例1:UPDATE BBSTopic SET tcontents = replace(replace(tcontents,'共产党','') ,'找死','') where tcontents like '%共产党%' or tcontents like '%找死%'
例2:UPDATE typetable SET type_description=REPLACE(type_description,'360','http://www.jb51.net');

mysql replace用法

1.replace into
replace into table (id,name) values('1','aa'),('2','bb')
此语句的作用是向表table中插入两条记录。如果主键id为1或2不存在
就相当于
insert into table (id,name) values('1','aa'),('2','bb')
如果存在相同的值则不会插入数据

2.replace(object,search,replace)

把object中出现search的全部替换为replace

select replace('www.jb51.net','w','Ww')--->WwWwWw.jb51.net

例:把表table中的name字段中的aa替换为bb

update table set name=replace(name,'aa','bb')
0 0
原创粉丝点击