删除 MySQL 中的尾部零?
使用 trim() 函数删除 MySQL 中的尾部零。以下是语法 −
select trim(yourColumnName)+0 As anyAliasName from yourTableName;
我们首先创建一个表 −
mysql> create table removeTrailingZero -> ( -> Number DECIMAL(10,4) -> ); Query OK, 0 rows affected (0.83 sec)
以下是使用 insert 指令在表中插入一些记录的查询 −
mysql> insert into removeTrailingZero values(10.789); Query OK, 1 row affected (0.19 sec) mysql> insert into removeTrailingZero values(89.90); Query OK, 1 row affected (0.18 sec) mysql> insert into removeTrailingZero values(8999.70); Query OK, 1 row affected (0.20 sec) mysql> insert into removeTrailingZero values(0.40); Query OK, 1 row affected (0.23 sec) mysql> insert into removeTrailingZero values(0.0); Query OK, 1 row affected (0.16 sec)
以下是使用 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
广告