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

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

WBOY
WBOYOriginal
2016-06-07 16:27:531198browse

最近有个朋友提到如何使用sql来删除一个字段中部分内容,于是就写了这篇文章,简单记过: 测试表如下: CREATE TABLE `t` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `domain` tinytext, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAU

最近有个朋友提到如何使用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 

查看替换结果

Statement:
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