FORMAT()在MySQL中使用,以正确的格式显示USD货币记录。让我们首先创建一个表-mysql> create table DemoTable
-> (
-> Amount DECIMAL(15,4)
-> );
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values(90948484);
mysql> insert into DemoTable values(1000000000);
mysql> insert into DemoTable values(1535353536);
mysql> insert into DemoTable values(773646463);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;+-----------------+
| Amount |
+-----------------+
| 90948484.0000 |
| 1000000000.0000 |
| 1535353536.0000 |
| 773646463.0000 |
+-----------------+
4 rows in set (0.00 sec)
这是在MySQL中正确显示货币记录的查询-mysql> select concat('USD ',format(Amount,2)) as Currency from DemoTable;
这将产生以下输出。在这里,我们以正确的格式显示USD货币记录-+----------------------+
| Currency |
+----------------------+
| USD 90,948,484.00 |
| USD 1,000,000,000.00 |
| USD 1,535,353,536.00 |
| USD 773,646,463.00 |
+----------------------+
4 rows in set (0.23 sec)