Home > Database > Mysql Tutorial > body text

MYSQL查询字符替换sql语句

WBOY
Release: 2016-06-07 17:51:47
Original
1453 people have browsed it

在mysql中替换字符中的内容我们使用了replace就可以实现,如下实例。

 代码如下 复制代码

mysql> update `table_name` set field = replace(field,'.rar','.7z');

table_name:要查询的表名,

field:表里的字段名,

replace(field,'.rar','.7z'); :正则匹配,把field字段里的 .rar 替换为 .7z

利用replace加正则来替换字符

 代码如下 复制代码


UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` LIKE '%from_str%'

说明:
table_name —— 表的名字
field_name —— 字段名
from_str —— 需要替换的字符串
to_str —— 替换成的字符串

下面是今天运行的两句SQL批量替换语句,如果用到的可以参考下!

 代码如下 复制代码

UPDATE boblog_blogs SET content = replace (content,'[mycode=xml]','[mycode=html]');

查询表 boblog_blogs 将 content 字段中的字符 [mycode=xml] 替换成 [mycode=html]

 

 代码如下 复制代码
UPDATE boblog_blogs SET content = replace (content,'[//mycode]','[/mycode]');

查询表 boblog_blogs 将 content 字段中的字符 [//mycode] 替换成 [/mycode]

 

 代码如下 复制代码
UPDATE boblog_blogs SET htmlstat=0 where htmlstat=1

由于mysql字符替换时使用正则速度不如直接替换建义大家不在万不得己不要使用mysql哦。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!