D/MySQL

[MySQL] CONCAT_WS()

yeon.Biju 2020. 4. 8. 14:28

MySQl 문자열 함수와 연산자

 

CONCAT_WS()

   - 문자열 이어붙이는 CONCAT() 의 특별한 형태, 구분자가 함께 한다.

 

CONCAT_WS(sperator, str1, str2)

의 형태

 

CONCAT_WS() stands for Concatenate With Sperator and is a special form of CONCAT(). The frist argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The sepatator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL.

 

mysql> SELECT CONCAT_WS(',','First name','Second name', 'Last name');
+--------------------------------------------------------+
| CONCAT_WS(',','First name','Second name', 'Last name') |
+--------------------------------------------------------+
| First name,Second name,Last name                       |
+--------------------------------------------------------+
1 row in set (0.00 sec)

 

mysql> SELECT CONCAT_WS(',','First name',NULL, 'Last name');
+-----------------------------------------------+
| CONCAT_WS(',','First name',NULL, 'Last name') |
+-----------------------------------------------+
| First name,Last name                          |
+-----------------------------------------------+
1 row in set (0.00 sec)