mysql之concat和concat_ws

#concat(str1,str2,....) ,拼接多个字符串,和空字符串拼接得NULL(所以如果需要可以加IFNULL(str,'')判断)
select concat('a','b'); #ab
select concat('a',NULL); #NULL
select concat('a',IFNULL(NULL,''));#a

#concat_ws(SEPARATOR,str1,str2,....),用固定符号拼接字符串,忽略NULL值,不忽略空字符串
select concat_ws('/','a','b'); #a/b
select concat_ws('/','a',null,'b'); #a/b
select concat_ws('/','a','','b');#a//b

posted @ 2021-12-31 17:18  愿闻其详。  阅读(204)  评论(0)    收藏  举报