Home > Database > Mysql Tutorial > mysql中使用replace替换某字段的部分内容_MySQL

mysql中使用replace替换某字段的部分内容_MySQL

WBOY
Release: 2016-06-01 13:05:21
Original
1007 people have browsed it

最近有个朋友提到如何使用sql来删除一个字段中部分内容,于是就写了这篇文章,简单记过:

测试表如下:

代码如下:


CREATE TABLE `t` (  
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
   `domain` tinytext,  
   PRIMARY KEY (`id`)  
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 

插入测试内容:

代码如下:


INSERT INTO t(domain) VALUES ('j054,j020,mc032,her302') 

替换表内容:

代码如下:


UPDATE t SET domain = (REPLACE(domain, ',her302', '')) WHERE id = 1 

查看替换结果

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