我想根据某些字符串分割以下字符串。我们该怎么做?
abc\\10.2.4\\string with spaces\\1.2.3-another-string\\def\\string_with_underscores
由“ def”分割
答案 0 :(得分:0)
您可以像以下查询中那样使用regexp_replace
:
with tab(str) as
(
select 'abc\\10.2.4\\string with spaces\\1.2.3-another-string\\def\\string_with_underscores'
from dual
)
select regexp_replace(str,'def.*','') str1,
regexp_replace(str,'.*def','') str2
from tab;
STR1 STR2
------------------------------------------------------- -------------------------
abc\\10.2.4\\string with spaces\\1.2.3-another-string\\ \\string_with_underscores
答案 1 :(得分:0)
这有好处吗?
SQL> with test (col) as
2 (select 'abc\\10.2.4\\string with spaces\\1.2.3-another-string\\def\\string_with_underscores' from dual)
3 select regexp_substr(replace(col, 'def', '#'), '[^#)]+', 1, level) res
4 from test
5 connect by level <= regexp_count(col, 'def') + 1;
RES
--------------------------------------------------------------------------------
abc\\10.2.4\\string with spaces\\1.2.3-another-string\\
\\string_with_underscores
SQL>
此选项不需要您预先知道 结果将得到多少个子字符串,它是 dynamic 。