为此,您可以使用REPLACE()
。让我们首先创建一个表-
mysql> create table DemoTable1506 -> ( -> Title text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1506 values('This is MySQL'); mysql> insert into DemoTable1506 values('This is Java language'); mysql> insert into DemoTable1506 values('This is MongoDB NoSQL database');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1506;
这将产生以下输出-
+--------------------------------+ | Title | +--------------------------------+ | This is MySQL | | This is Java language | | This is MongoDB NoSQL database | +--------------------------------+ 3 rows in set (0.00 sec)
以下是删除两个单词之间的空格的查询-
mysql> update DemoTable1506 -> set Title=replace(Title,' is ', ' is'); Rows matched: 3 Changed: 3 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1506;
这将产生以下输出-
+-------------------------------+ | Title | +-------------------------------+ | This isMySQL | | This isJava language | | This isMongoDB NoSQL database | +-------------------------------+ 3 rows in set (0.00 sec)