如何在 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)

更新日期:30-Jul-2019

1K+ 次瀏覽

開啟職業生涯

完成課程即可獲得認證

立刻開始
廣告
© . All rights reserved.