「MariaDB 10.6.4」数値を3桁毎にカンマで区切りで表示する

環境
windows 10 64bit
MariaDB 10.6.4
書式
FORMAT(X,D[,locale])
数値 X を '#,###,###.##’ のような書式に変換し、小数点第 D 位に丸めて、その結果を文字列として返します。
D が 0 の場合は、結果に小数点または小数部が含まれません。
FORMAT 関数は引数に指定した数値を 3 桁毎にカンマで区切って整形し文字列として取得するために使用します。

使用例1

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT FORMAT( 123456789,0 ) result;
+-------------+
| result |
+-------------+
| 123,456,789 |
+-------------+
1 row in set (0.185 sec)
MariaDB [(none)]> SELECT FORMAT( 123456789,0 ) result; +-------------+ | result | +-------------+ | 123,456,789 | +-------------+ 1 row in set (0.185 sec)
MariaDB [(none)]> SELECT FORMAT( 123456789,0 ) result;
+-------------+
| result      |
+-------------+
| 123,456,789 |
+-------------+
1 row in set (0.185 sec)

使用例2
少数を使用すると、四捨五入されます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> SELECT FORMAT( 12345678.9,0 ) result;
+------------+
| result |
+------------+
| 12,345,679 |
+------------+
1 row in set (0.068 sec)
MariaDB [(none)]> SELECT FORMAT( 12345678.9,0 ) result; +------------+ | result | +------------+ | 12,345,679 | +------------+ 1 row in set (0.068 sec)
MariaDB [(none)]> SELECT FORMAT( 12345678.9,0 ) result;
+------------+
| result     |
+------------+
| 12,345,679 |
+------------+
1 row in set (0.068 sec)

 

MariaDB

Posted by arkgame