字段截取

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值