Home > Database > Mysql Tutorial > mysql替换replace()实现mysql替换字符串

mysql替换replace()实现mysql替换字符串

WBOY
Release: 2016-06-07 17:53:11
Original
1413 people have browsed it

mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便,mysql 替换函数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 —— 替换成的字符串


例子

MySQL Replace 替换函数语法:

 代码如下 复制代码

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, "find this string", "replace found string with this string");

Replace 替换函数案例:

 代码如下 复制代码

update client_table set url = replace(url, "111cn.net", )

这样就能将MySQL中所有字符串替换成新的了。

例2

',
 '' );
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,
 '../../../../../../',
 'http://special.fsaf/meal/' );
 代码如下 复制代码

示例:
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