如何使 MySQL 中的數字“人可讀”?


要把數字“變成人可讀”格式(即包含分隔符),你需要使用 format()。讓我們先建立一個表 -

mysql> create table DemoTable859(Number bigint);
Query OK, 0 rows affected (1.54 sec)

使用 insert 命令在表中插入一些記錄 -

mysql> insert into DemoTable859 values(747464646473737);
Query OK, 1 row affected (0.45 sec)
mysql> insert into DemoTable859 values(3836365366464);
Query OK, 1 row affected (0.71 sec)
mysql> insert into DemoTable859 values(8376437647433);
Query OK, 1 row affected (0.46 sec)

使用 select 語句顯示錶中的所有記錄 -

mysql> select *from DemoTable859;

將產生以下輸出 -

+-----------------+
| Number          |
+-----------------+
| 747464646473737 |
| 3836365366464   |
| 8376437647433   |
+-----------------+
3 rows in set (0.00 sec)

以下是使 MySQL 中的數字“變成人可讀”格式的查詢 -

mysql> select format(Number, 0) AS HumanReadableFormat from DemoTable859;

將產生以下輸出 -

+---------------------+
| HumanReadableFormat |
+---------------------+
| 747,464,646,473,737 |
| 3,836,365,366,464   |
| 8,376,437,647,433   |
+---------------------+
3 rows in set (0.00 sec)

更新時間: 03-9 月 -2019

365 次瀏覽

開啟您的職業生涯

完成課程後獲得認證

開始
廣告
© . All rights reserved.