从 MySQL 中的两个单词之间移除空格?
为此,您可以使用 REPLACE()。让我们首先创建一个表 −
mysql> create table DemoTable1506 -> ( -> Title text -> ); Query OK, 0 rows affected (0.70 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1506 values('This is MySQL'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1506 values('This is Java language'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1506 values('This is MongoDB NoSQL database'); Query OK, 1 row affected (0.60 sec)
使用 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'); Query OK, 3 rows affected (0.14 sec) 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)
广告