加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle split函数实现,按顺序获取,两个字符直接的空值也能获取

发布时间:2020-12-12 15:30:50 所属栏目:百科 来源:网络整理
导读:参考了网上的代码修改实现,修改后可以按顺序获取数组 with str as (select 'first field,second field,third field,' as text,',' as split_ch from dual where rownum = 1)select case when text = ' ' then null else replace(text,' ',' ') end text,ind

参考了网上的代码修改实现,修改后可以按顺序获取数组

with str as (select 'first field,second field,third field,' as text,',' as split_ch from dual where rownum = 1)
select case
         when text = ' ' then
          null
         else
          replace(text,'  ',' ')
       end text,indext
  from (SELECT REGEXP_SUBSTR(replace(replace(str.text,' ','  '),str.split_ch || str.split_ch,str.split_ch || ' ' || str.split_ch),'[^' || str.split_ch || ']+',1,rownum) AS TEXT,ROWNUM AS INDEXT
          FROM dual,str
        CONNECT BY ROWNUM <= LENGTH(str.text) -
                   LENGTH(REPLACE(str.text,str.split_ch,'')) + 1)
 ORDER BY INDEXT

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读