从左边截取字符串 用法:left(str,length), 即:left(被截取字符串,截取长度)
select left('fuyinghao',4);
结果:fuyi
从右边截取字符串 用法:right(str,length), 即:right(被截取字符串,截取长度)
select right('fuyinghao',4);
结果:ghao
有两种用法:
substring(str,pos), 即:substring(被截取字符串,从第几位开始截取)
substring(str,pos,length), 即:substring(被截取字符串,从第几位开始截取,截取长度)
select substring('fuyinghao',3);结果:yinghao
select substring('fuyinghao',3,4);结果:ying
select substring('fuyinghao',-3);结果:hao
select substring('fuyinghao',-3,2);结果:ha
用法:substring_index(str,keyword,count), 即:substring_index(被截取字符串,关键字,关键字出现的次数)
select substring_index('fuyinghao','i',1);结果:fuy
select substring_index('fuyinghao','i',-1);结果:nghao
select substring_index('fuyinghao','z',2);结果:fuyinghao