Oracle11g oracle以逗号分隔带引号的字符串

Oracle11g oracle以逗号分隔带引号的字符串,oracle11g,regexp-replace,regexp-substr,Oracle11g,Regexp Replace,Regexp Substr,我发现很多这样的问题,但没有一个是100%适合我的。我有oracle 11g express 我有那根绳子 'abcd,123,,defoifcd,"comma, in string",87765,,,hello' 这意味着通常用逗号分隔数据,但在一个系列中可能更多地是空数据,如果数据中有逗号,则会引用它 到目前为止,最好的reg exp就是那个 '("[^"]*"|[^,]+)' 但这会将使用该查询的所有空数据放在末尾 with test as (select 'abcd,123,,d

我发现很多这样的问题,但没有一个是100%适合我的。我有oracle 11g express

我有那根绳子

'abcd,123,,defoifcd,"comma, in string",87765,,,hello'
这意味着通常用逗号分隔数据,但在一个系列中可能更多地是空数据,如果数据中有逗号,则会引用它

到目前为止,最好的reg exp就是那个

'("[^"]*"|[^,]+)'
但这会将使用该查询的所有空数据放在末尾

with test as 
(select 
'abcd,123,,defoifcd,"comma, in string", 87765,,,hello'
str from dual  
)  
select REGEXP_SUBSTR(str, '("[^"]*"|[^,]+)', 1, rownum) split
from test  
connect by level <= length (regexp_replace (str, '("[^"]*"|[^,]+)'))  + 1;
但是regexp\u replace只替换第一次出现的空数据

select 
regexp_replace('abcd,123,,defoifcd,"comma, in string",87765,,,hello', '(,,)', ',n/a,')
str from dual;  

提前谢谢

这似乎可以工作并处理空值:

SQL> with test as
    (select
    'abcd,123,,defoifcd,"comma, in string", 87765,,,hello'
    str from dual
    )
    select trim('"' from REGEXP_SUBSTR(str, '(".*?"|.*?)(,|$)', 1, level, NULL, 1)) split
    from test
    connect by level<=length(regexp_replace(str,'".*?"|[^,]*'))+1;

SPLIT
----------------------------------------------------
abcd
123

defoifcd
comma, in string
 87765


hello

9 rows selected.

SQL>

这篇文章为解决方案提供了动力:

这似乎有效,可以处理空值:

SQL> with test as
    (select
    'abcd,123,,defoifcd,"comma, in string", 87765,,,hello'
    str from dual
    )
    select trim('"' from REGEXP_SUBSTR(str, '(".*?"|.*?)(,|$)', 1, level, NULL, 1)) split
    from test
    connect by level<=length(regexp_replace(str,'".*?"|[^,]*'))+1;

SPLIT
----------------------------------------------------
abcd
123

defoifcd
comma, in string
 87765


hello

9 rows selected.

SQL>

这篇文章为解决方案提供了动力:

你已经看过了吗?这是使用replace而不是regexp_replace在…中放置一个虚拟值,是的,这种替换确实是一个好主意,您已经看过了吗?这是使用replace而不是regexp_replace在…中放置一个虚拟值,是的,这种替换确实是一个好主意