目录:
字符串函数:
1.1 字符串合并 concat 、concat_ws
①concat(s1, s2…,sn):将多个字符串合并起来。
concat不仅可以接受字符串还能接受其他类型。
select concat("sunny " , " is" , " a", " teacher") as 'concat'
结果:sunny is a teacher
select CONCAT(CURDATE(),"‐", 12.34);
结果:2020-03-03‐12.34
②concat_ws(sep, s1, …sn):用分隔符将字符串连接。
select concat_ws(" ", "sunny" , "is" , "a", "teacher") as 'desc';
结果:sunny is a teacher
select concat_ws("+", "sunny" , "is" , "a", "teacher") as 'desc';
sunny+is+a+teacher
sep不能为null不然后续的都会被忽略掉。
select concat_ws(NULL, "sunny" , "is" , "a", "teacher") as 'desc';
结果:什么都没有,为空
1.2 字符串比较 strcmp
strcmp(str1, str2): 如果str1大于str2 返回结果1, 如果str1小于str2 返回‐1, str1等于str2返回0
select STRCMP("abc","bcd");
select strcmp("a","A");
select STRCMP("abc","abb");