mysql使用replace函数进行字符串替换
时间:2014-11-23 15:35 来源:linux.it.net.cn 作者:IT
mysql使用replace函数进行字符串替换
先举两个示例:
复制代码代码如下:
Update dede_addonsoft SET dxylink=REPLACE(dxylink, '.zip', '.rar') where aid > 45553;
复制代码代码如下:
update `table_name` set field = replace(field,'.rar','.7z');
table_name:要查询的表名,
field:表里的字段名,
replace(field,'.rar','.7z'); :正则匹配,把field字段里的 .rar 替换为 .7z
MySQL正则表达式替换,字符替换方法
1
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'))
2
where 1=1;
3
update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';
MySQL replace函数替换字符串
MySQL replace函数经常用到,下面介绍MySQL replace函数的用法。
数据转换要用到mysql的MySQL replace函数。
比如你要将表 tb1里面的 f1字段的abc替换为def
1
UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');
2
3
REPLACE(str,from_str,to_str)
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串:
1
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
2
-> 'WwWwWw.mysql.com'
这个函数是多字节安全的。
示例:
01
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
02
'</td>',
03
'' );
04
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
05
'</tr>',
06
'' );
07
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
08
'<tr>',
09
'' );
10
UPDATE `dede_archives` SET title= REPLACE ( title,
11
'大洋新闻 - ',
12
'' );
13
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
14
'../../../../../../',
15
'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.163.com','w','Ww')--->WwW wWw.163.com
例:把表table中的name字段中的 aa替换为bbupdate table set name=replace(name,'aa','bb')。
(责任编辑:IT)
| mysql使用replace函数进行字符串替换 先举两个示例:
复制代码代码如下:
Update dede_addonsoft SET dxylink=REPLACE(dxylink, '.zip', '.rar') where aid > 45553;
复制代码代码如下:
update `table_name` set field = replace(field,'.rar','.7z');
table_name:要查询的表名,
MySQL replace函数替换字符串
在字符串 str 中所有出现的字符串 from_str 均被 to_str替换,然后返回这个字符串:
这个函数是多字节安全的。
mysql replace |