要替换,请使用REPLACE()
MySQL中的函数。让我们首先创建一个表-
mysql> create table DemoTable ( Number varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('+916578675547'); mysql> insert into DemoTable values('+918976676564'); mysql> insert into DemoTable values('+919800087678');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+---------------+ | Number | +---------------+ | +916578675547 | | +918976676564 | | +919800087678 | +---------------+ 3 rows in set (0.00 sec)
以下是用空格替换“ +”(加号)的查询-
mysql> update DemoTable set Number=replace(Number, '+', ' '); Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable
这将产生以下输出-
+---------------+ | Number | +---------------+ | 916578675547 | | 918976676564 | | 919800087678 | +---------------+ 3 rows in set (0.00 sec)