如何使用MySQL UPDATE删除连字符?
要使用MySQL更新删除连字符,可以使用replace()函数。语法如下-
update yourTableName set yourColumnName=replace(yourColumnName,'-', '' );
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table removeHyphensDemo -> ( -> userId varchar(100) -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into removeHyphensDemo values('John-123-456');
mysql> insert into removeHyphensDemo values('Carol-9999-7777-66555');
mysql> insert into removeHyphensDemo values('123456-Bob-8765');
mysql> insert into removeHyphensDemo values('1678-9870-Sam');使用select语句显示表中的所有记录。查询如下-
mysql> select *from removeHyphensDemo;
这是输出-
+-----------------------+ | userId | +-----------------------+ | John-123-456 | | Carol-9999-7777-66555 | | 123456-Bob-8765 | | 1678-9870-Sam | +-----------------------+ 4 rows in set (0.00 sec)
这是删除连字符的查询-
mysql> update removeHyphensDemo -> set userId=replace(userId,'-',''); Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录。查询如下-
mysql> select *from removeHyphensDemo;
这是不带连字符的输出-
+--------------------+ | userId | +--------------------+ | John123456 | | Carol9999777766555 | | 123456Bob8765 | | 16789870Sam | +--------------------+ 4 rows in set (0.00 sec)
热门推荐
5 祝福语简短七夕
10 宝宝100日简短祝福语
11 恭喜订婚的祝福语简短
12 入学校简短祝福语
13 给儿子生日祝福语 简短
14 小孩想说的祝福语简短
15 新婚祝福语简短句子
16 开业祝福语简短大气的
17 给新年祝福语简短独特
18 写字生日祝福语简短独特