sql语句中SUBSTRING,SUBSTRING_INDEX,LOCATE用法详解
SUBSTRING(string,position)截取字符串
–string要截取字符串,position位数字,从string第多少个开始截取
SUBSTRING_INDEX(str, delimiter, count)分割字符串
–str要分割的字符串,delimiter分隔符,count计数,如果count是正数,那么就是从左往右数,第N个分隔符的左边的全部内容;如果是负数,那么就是从右边开始数,第N个分隔符右边的所有内容
LOCATE(subStr,string) :函数返回subStr在string中出现的位置
SUBSTRING_INDEX(
SUBSTRING_INDEX(f.task_encode, ‘->’, 1),
“-”,
1
) souceIP,
SUBSTRING(
SUBSTRING_INDEX(f.task_encode, ‘->’, 1),
LOCATE(
‘-’,
SUBSTRING_INDEX(f.task_encode, ‘->’, 1)
) + 1
) soucePon,
SUBSTRING_INDEX(
SUBSTRING_INDEX(f.task_encode, ‘->’, - 1),
“-”,
1
) targetIP,
substring(
SUBSTRING_INDEX(f.task_encode, ‘->’, - 1),
LOCATE(
‘-’,
SUBSTRING_INDEX(f.task_encode, ‘->’, - 1)
) + 1
) targetPon