在 MySQL 中删除尾随零?
mysqlmysqli database更新于 2025/1/19 20:28:17
使用 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
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

