Home  >  Article  >  Database  >  replace MYSQL字符替换函数sql语句分享(正则判断)

replace MYSQL字符替换函数sql语句分享(正则判断)

WBOY
WBOYOriginal
2016-06-07 18:07:381610browse

最近更新网站发现一些字段的值不是预期的效果,需要替换下值,通过下面的sql语句,直接执行就可以了

代码如下:
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正则表达式替换,字符替换方法

两句SQL,都是字符替换,比较好用。

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')) where 1=1;

update comment set author_url=REPLACE(author_url,'sohu','sina') where author_url REGEXP 'www.sohu.com';

MySQL replace函数替换字符串

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,
'',
'' );
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
'',
'' );
UPDATE `dede_addonarticle` SET body = REPLACE ( body,
'',
'' );
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.163.com','w','Ww')--->WwW wWw.163.com

例:把表table中的name字段中的 aa替换为bbupdate table set name=replace(name,'aa','bb')
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn