有时候需要处理字段内的空格,大概分几种场景:
1、去掉字符串两边的空格
2、去掉字符串左边的空格
3、去掉字符串右边的空格
4、去掉字段中所有空格
操作分别如下:
1、去掉字符串两边的空格:
首先,我们看一下两边有空格不删除的情况下的样子:
mysql> select ' Hello ' as Trim;
+-------------+
| Trim |
+-------------+
| Hello |
+-------------+
1 row in set (0.00 sec)
进行删除两边空格操作:
mysql>
select trim(' Hello ') as Trim;
+-------+
| Trim |
+-------+
| Hello |
+-------+
1 row in set (0.00 sec)
2、删除右测空格:
mysql>
select rtrim(' Hello ') as Trim;
+----------+
| Trim |
+----------+
| Hello |
+----------+
1 row in set (0.00 sec)
3、删除左侧空格:
mysql>
select ltrim(' Hello ') as Trim;
+----------+
| Trim |
+----------+
| Hello |
+----------+
1 row in set (0.00 sec)
4、去掉字段中所有空格:
update `Gao` set `Guitars`=replace(`Guitars`,' ','');
阅读(2525) | 评论(0) | 转发(0) |