Home > Database > Mysql Tutorial > 批量替换 MySQL 指定字段中的字符串

批量替换 MySQL 指定字段中的字符串

WBOY
Release: 2016-06-07 18:01:37
Original
886 people have browsed it

批量替换 MySQL 指定字段中的字符串是数据库应用中很常见的需求,但是有很多初学者在遇到这种需求时,通常都是用脚本来实现;其实,MySQL 内置的有批量替换语法,效率也会高很多;想了解具体方法,继续阅读本文吧 :)

批量替换的具体语法是:
代码如下:
UPDATE 表名 SET
指定字段 = replace(指定字段, '要替换的字符串', '想要的字符串')
WHERE 条件;

如果你想把 article 表中 ID 小于5000的记录,content 字段中“解决”替换成“解放”,那么语法就是:
代码如下:
UPDATE article SET
content = replace(content, '解决', '解放')
WHERE ID
是不是很方便 :)
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