Home > Database > Mysql Tutorial > body text

mysql replace函数替换字符串

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

在mysql中要替换字段中的指定字符或字符串我们用得最多的就是replace()函数了,下面我来讲述一下replace()函数用法。

sql语句:

 代码如下 复制代码

update table_name set field_name=replace(field_name,’from_str’,'to_str’)

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

例如

表: abc
字段:xxx
被换的字符串: a
替换成的字符串:c

 代码如下 复制代码

update abc set xxx=replace(xxx,’a',’c')

','' );
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,'

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