当前位置: 移动技术网 > IT编程>数据库>Mysql > mySQL中replace的用法

mySQL中replace的用法

2017年12月12日  | 移动技术网IT编程  | 我要评论

沉默的证人在线观看,网游之纵横乱世天下,小岛源治

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','//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')

mysql replace函数我们经常用到,下面就为您详细介绍mysql replace函数的用法,希望对您学习mysql replace函数方面能有所启迪。

最近在研究cms,在数据转换的时候需要用到mysql的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'
这个函数是多字节安全的。

示例:
update `dede_addonarticle` set body = replace ( body,
'</td>',
'' );
update `dede_addonarticle` set body = replace ( body,
'</tr>',
'' );
update `dede_addonarticle` set body = replace ( body,
'<tr>',
'' );
update `dede_archives` set title= replace ( title,
'大洋新闻 - ',
'' );
update `dede_addonarticle` set body = replace ( body,
'../../../../../../',
'http://special.dayoo.com/meal/' );

mysql replace

用法1.replace intoreplace into table (id,name) values(‘1‘,‘aa‘),(‘2‘,‘bb‘)
此语句的作用是向表table中插入两条记录。
2.replace(object, search,replace)
把object中出现search的全部替换为replaceselect replace(‘www.jb51.net‘,‘w‘,‘ww‘)--->www www.jb51.net

例:把表table中的name字段中的 aa替换为bbupdate table set name=replace(name,‘aa‘,‘bb‘)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网