在MySQL中删除尾随零?
使用trim()函数删除MySQL中的尾随零零。以下是语法-
select trim(yourColumnName)+0 As anyAliasName from yourTableName;
让我们首先创建一个表-
mysql> create table removeTrailingZero -> ( -> Number DECIMAL(10,4) -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into removeTrailingZero values(10.789); mysql> insert into removeTrailingZero values(89.90); mysql> insert into removeTrailingZero values(8999.70); mysql> insert into removeTrailingZero values(0.40); mysql> insert into removeTrailingZero values(0.0);
以下是使用select语句显示表中所有记录的查询-
mysql> select * from removeTrailingZero;
这将产生以下输出-
+-----------+ | Number | +-----------+ | 10.7890 | | 89.9000 | | 8999.7000 | | 0.4000 | | 0.0000 | +-----------+ 5 rows in set (0.00 sec)
以下是删除尾随零的查询-
mysql> select trim(Number)+0 As WithoutTrailingZero from removeTrailingZero;
这将产生以下输出-
+---------------------+ | WithoutTrailingZero | +---------------------+ | 10.789 | | 89.9 | | 8999.7 | | 0.4 | | 0 | +---------------------+ 5 rows in set (0.00 sec
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短