0x01 concat()
注意:返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null
用途:连接一个或多个字符串
语法:concat(str1,str2…)
# 不带NULL的
mysql> select concat('123','456','aaa','789');
+---------------------------------+
| concat('123','456','aaa','789') |
+---------------------------------+
| 123456aaa789 |
+---------------------------------+
# 带NULL的
mysql> select concat('123','456',NULL,'aaa','789');
+--------------------------------------+
| concat('123','456',NULL,'aaa','789') |
+--------------------------------------+
| NULL |
+--------------------------------------+
1 row in set
0x02 concat_ws()
注意:如果 concat_ws 的参数有NULL会无视掉
用途:使用固定连接符连接一个或多个字符串
语法:concat_ws(separator,str1,str2…)
# 不带NULL的
mysql> select concat_ws('-','aa','bb','cc');
+------------------------+
| concat_ws('-','aa','bb','cc') |
+------------------------+
| aa-bb-cc |
+------------------------+
1 row in set
# 带NULL的
mysql> select concat_ws('-','aa','bb',NULL,'cc');
+-----------------------------+
| concat_ws('-','aa','bb',NULL,'cc') |
+-----------------------------+
| aa-bb-cc |
+-----------------------------+
1 row in set