如何在 MySQL 记录中添加千分位分隔符?
为此,请使用 FORMAT() 方法。我们首先创建一个表 -
mysql> create table DemoTable -> ( -> Amount DECIMAL(10,2) -> ); Query OK, 0 rows affected (0.45 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable values(84848757.60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(95868685.50); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(4242342.36); Query OK, 1 row affected (0.21 sec)
使用 select 语句从表中显示所有记录 -
mysql> select *from DemoTable;
输出
+-------------+ | Amount | +-------------+ | 84848757.60 | | 95868685.50 | | 4242342.36 | +-------------+ 3 rows in set (0.00 sec)
以下是对 MySQL 设置分隔符的查询 -
mysql> select format(Amount,2) from DemoTable;
输出
+------------------+ | format(Amount,2) | +------------------+ | 84,848,757.60 | | 95,868,685.50 | | 4,242,342.36 | +------------------+ 3 rows in set (0.00 sec)
广告