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

前端之家收集整理的这篇文章主要介绍了oracle split函数实现,按顺序获取,两个字符直接的空值也能获取前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

猜你在找的Oracle相关文章