美文网首页程序员
oracle根据分隔符将一行拆分为多行

oracle根据分隔符将一行拆分为多行

作者: 某月某日_5ced | 来源:发表于2019-10-11 09:57 被阅读0次

--oracle根据分隔符将一行拆分为多行

with tmp as --临时数据集

(select '1,2,3' val

    from dual

  union all

  select '4,5,6' val

    from dual)

select regexp_substr(t.val, '[^,]+', 1, t2.lv)--截取对应行数的数据

  from tmp t,

      (select level lv--生成行数序列数据 1到最大行数

          from (select max(regexp_count(a.val, '[^,]+', 1)) r_count--计算数据集中拆分后最大的行数

                  from tmp a) b

        connect by level <= b.r_count) t2

where regexp_substr(t.val, '[^,]+', 1, t2.lv) is not null-- 排除掉空的数据

相关文章

网友评论

    本文标题:oracle根据分隔符将一行拆分为多行

    本文链接:https://www.haomeiwen.com/subject/cbftmctx.html