Home >Database >Mysql Tutorial >Mysql两种情况下更新字段中部分数据的方法_MySQL

Mysql两种情况下更新字段中部分数据的方法_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:24:21868browse

bitsCN.com Mysql更新字段中部分数据第一种情况: 

update tab set A = concat(substring(A,1,3),'bbb');


从A的1个字符开始取3个字符,加上'bbb',再写入a中,如果A原始值为'123aaa',那么更新之后为'123bbb'了。

如果我们要将字段A值中的包含的1,替换成2呢?
例如:a=2211,现在要替换成2222,就是把1换成2
SQl语句这么写:

update table set a=REPLACE(a,'1','2');
 bitsCN.com

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