Home > Database > Mysql Tutorial > body text

MYSQL 批量替换之replace语法的使用详解_MySQL

WBOY
Release: 2016-06-01 13:25:16
Original
968 people have browsed it

bitsCN.com 实际需求中,需要对某张表某字段里面的内容进行批量替换,普通的思考流程如下:
SELECT出来
str_replace替换
UPDATE写入
实际这样极其浪费资源以及消耗资源,MYSQL内置了一个批量替换的语法

UPDATE table SET field = replace(field,'被替换','替换成') 

直接就替换了,后面也可以跟WHERE 条件语句
支持多个词同时被替换

UPDATE table SET field = replace(field,'被替换1','替换成1'),field = replace(field,'被替换2','替换成2') 

很强大吧,后面那个一次性更换多个网上是没有的列子,现在记录下来
bitsCN.com

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