如何使用 MySQL 檢視為數字新增分隔符?


我們首先建立一個表 −

mysql> create table DemoTable
(
   StudentId int
);
Query OK, 0 rows affected (0.62 sec)

使用 insert 命令向表中插入一些記錄 −

mysql> insert into DemoTable values(343898456);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable values(222333444);
Query OK, 1 row affected (0.22 sec)

以下查詢使用 select 語句從表中顯示所有記錄 −

mysql> select *from DemoTable;

這會產生以下輸出 −

+-----------+
| StudentId |
+-----------+
| 343898456 |
| 222333444 |
+-----------+
2 rows in set (0.00 sec)

下面是建立檢視的查詢 −

mysql> create view myView_DemoTable as select format(StudentId, 0) AS `StudentId` from DemoTable;
Query OK, 0 rows affected (0.18 sec)
Let us check the records of view table:
mysql> select *from myView_DemoTable;

這會產生以下輸出 −

+-------------+
| StudentId   |
+-------------+
| 343,898,456 |
| 222,333,444 |
+-------------+
2 rows in set (0.04 sec)

更新於: 30-07-2019

150 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始
廣告