使用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