[MySQL] CONCAT()
MySQL 문자열 함수와 연산자
CONCAT()
- 문자열 이어붙이기 정도
CONCAT(str1, str2...)
의 형태
Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent nonbinary string form.
CONCAT() returns NULL if any argument is NULL.
mysql> SELECT CONCAT ('My','S', 'QL');
+-------------------------+
| CONCAT ('My','S', 'QL') |
+-------------------------+
| MySQL |
+-------------------------+
1 row in set (0.00 sec)
위와 같이 쓰면 오라클에서는 ORA-00909: invalid number of arguments 와 같은 오류를 뱉어내는데...
mysql> SELECT CONCAT ('My',NULL, 'QL');
+--------------------------+
| CONCAT ('My',NULL, 'QL') |
+--------------------------+
| NULL |
+--------------------------+
1 row in set (0.00 sec)
mysql> SELECT CONCAT (14, 3);
+----------------+
| CONCAT (14, 3) |
+----------------+
| 143 |
+----------------+
1 row in set (0.00 sec)
이건 오라클도 동일하게 나옴
For quoted strings, concatenation can be performed by placing the string next to each other.
mysql> SELECT 'My' 'S' 'QL' ;
+-------+
| My |
+-------+
| MySQL |
+-------+
1 row in set (0.00 sec)
이건 역시 오라클에서는 에러를 내뿜어준다.
오라클에서 SELECT 'My'||'S'||'QL' FROM DUAL ;
는 잘 작동하지만
MySQL 에서는 그렇지 않다.
mysql> SELECT 'My'||'S'||'QL';
+-----------------+
| 'My'||'S'||'QL' |
+-----------------+
| 0 |
+-----------------+
1 row in set, 5 warnings (0.00 sec)