Home > Database > Mysql Tutorial > body text

mysql 字符替换命令总结

WBOY
Release: 2016-06-07 17:52:17
Original
1191 people have browsed it

本文章收藏了大量的常用的收集到了批量替换语句与实例,有需要学习的朋友可参考一下。

UPDATE 表名 SET 指定字段 = replace(指定字段, ’要替换的字符串’, ’想要的字符串’) WHERE 条件;今天用到的删除空格的

例一:

 代码如下 复制代码

UPDATE `qlj_joke` SET content = replace(content,' ','') ;

例二:

把“wp_posts”表里的“post_content”字段里的“PJBlog”全部替换成“WordPress”

 代码如下 复制代码

update wp_posts set post_content=REPLACE(post_content,'PJBlog','WordPress')

例三:

把“wp_comments”表里的“comment_content”字段里的“PJBlog”全部替换成“WordPress”

update wp_comments set comment_content=REPLACE(comment_content,'PJBlog','WordPress')
执行完了这段代码之后就会有提示多少条被替换了:

例四

根据条件增加字段的内容,如把file_number=1的记录的logical_name字段的内容前面加上tmp,后面加上end

 代码如下 复制代码

update backupfile set logical_name=REPLACE(logical_name,logical_name,'tmp'+logical_name+' end ') where file_number=1

例五REPLACE INTO

REPLACE INTO  fanwe_order(id,sn)  VALUES('33','测试replace into 使用')  结果:受影响的行数:

2

SELECT * FROM fanwe_order WHERE sn='测试replace into 使用'
 结果:查出 一行记录

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!