「MariaDB」CONCAT_WS関数で区切り文字を指定して文字列を結合する

2022年3月23日

環境
MariaDB 10.6.4

書式1
区切り文字(,)に数値を指定する場合、文字列として扱われます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 123, -345 ) result;
+-----------+
| result |
+-----------+
| 123, -345 |
+-----------+
1 row in set (0.000 sec)
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 123, -345 ) result; +-----------+ | result | +-----------+ | 123, -345 | +-----------+ 1 row in set (0.000 sec)
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 123, -345 ) result;
+-----------+
| result    |
+-----------+
| 123, -345 |
+-----------+
1 row in set (0.000 sec)

書式2
区切り文字(,)にnullを指定する場合

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 'study', 'world',null ) result;
+--------------+
| result |
+--------------+
| study, world |
+--------------+
1 row in set (0.001 sec)
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 'study', 'world',null ) result; +--------------+ | result | +--------------+ | study, world | +--------------+ 1 row in set (0.001 sec)
MariaDB [testdb]> SELECT CONCAT_WS( ', ', 'study', 'world',null ) result;
+--------------+
| result       |
+--------------+
| study, world |
+--------------+
1 row in set (0.001 sec)

 

MariaDB

Posted by arkgame