1.split_part
SPLIT_PART ( string , delimiter , field )
delimiter:分隔符
2.left
LEFT ( string‑expr, length )
3.right
RIGHT ( string‑expr, length )
4.substr
SUBSTR ( string , position [ , extent ] )
select word
,split_part(word,'-',1) as part1
,split_part(word,'-',2) as part2
,left(word,5) as left_word
,right(word,4) as right_word
,substr(word,6,4) as substr_word
from tmp
mysql
SUBSTRING_INDEX(
str
,delim
,count
)
str
在 count
出现分隔符 之前 从字符串返回子字符串 delim
。 如果 count
为正,则返回最终分隔符左侧的所有内容(从左侧开始计算)。 如果 count
为负,则返回最终分隔符右侧的所有内容(从右侧开始计算)。
select word
,left(word,5) as left_word
,right(word,4) as right_word
,substr(word,6,4) as substr_word
,substring_index(word,'-',1) as part1
,substring_index(word,'-',2) as part2
,substring_index(word,'-',-1) as 'part -1'
,substring_index(word,'-',-2) as 'part -2'
from (select 'abcd-1234-ghjk' as word) t