oracle 特殊转字符串,有挑战性,超复杂字符串拆分(特殊情况的行转列)

SQL> with t as

2   (select regexp_substr(str, '[^\^]+', 1, level) as val

3      from (select 'A|RQ:0^B|SPF:3,0^C|RQ:3,1' as str from dual)

4    connect by level <= regexp_count(str, '\^') + 1),

5  s as

6   (select substr(val, 1, instr(val, '|', 1) - 1) as val_type,

7           substr(val,

8                  instr(val, '|', 1) + 1,

9                  instr(val, ':', 1) - instr(val, '|', 1) - 1) as val_option,

10           substr(val, instr(val, ':', 1) + 1) as val_res

11      from t),

12   a as (select val_type,val_option,val_res,regexp_count(val_res,',')+1 as cnt

13            from s)

14  select a.val_type,

15         a.val_option,

16         regexp_substr(a.val_res,'[^,]+',1,b.n) val_res

17    from a,(select level n

18              from dual

19           connect by level<= (select max(cnt) from a)) b

20   where a.cnt >= b.n

21  /

VAL_TYPE                                                                         VAL_OPTION                                                                       VAL_RES

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --------------------------------------------------------------------------------

A                                                                                RQ                                                                               0

B                                                                                SPF                                                                              3

B                                                                                SPF                                                                              0

C                                                                                RQ                                                                               3

C                                                                                RQ                                                                               1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值