如何在 oracle 中拆分由 space 分隔的字符串并将每个单词添加到 Oracle 11g 中的不同行?
How to split a string seperated by space in oracle and add each word to a different row in Oracle 11g?
我正在尝试拆分字符串并将每个单词添加到单独的行中。
with data as (
select 100 as id, 'python java' as src from dual
)
select id, level as lvl,
regexp_substr( src || '" "' , '([[:space:]0-9/:])', 1, level, null, 1 ) as token
from data
connect by level <= regexp_count( src || '" "' , '([[:space:]0-9/:])' )
and prior id = id
and prior sys_guid() is not null
;
我希望 python 和 java 在不同的行中。
您的正则表达式似乎有点混乱。我想你想要更像的东西:
regexp_substr( src , '(.*?)([[:space:]0-9/:]|$)', 1, level, null, 1 )
您可以将 regexp_substr()
和 regexp_count()
与 connect by level<...
表达式组合使用:
with t as
(
select 100 as id, 'python java' as src from dual
)
select id, level as lvl, regexp_substr(src, '[^[:space:]]+',1,level) as token
from t
connect by level<= regexp_count(src,'[[:space:]]')+1
and prior id = id
and prior sys_guid() is not null;
我正在尝试拆分字符串并将每个单词添加到单独的行中。
with data as (
select 100 as id, 'python java' as src from dual
)
select id, level as lvl,
regexp_substr( src || '" "' , '([[:space:]0-9/:])', 1, level, null, 1 ) as token
from data
connect by level <= regexp_count( src || '" "' , '([[:space:]0-9/:])' )
and prior id = id
and prior sys_guid() is not null
;
我希望 python 和 java 在不同的行中。
您的正则表达式似乎有点混乱。我想你想要更像的东西:
regexp_substr( src , '(.*?)([[:space:]0-9/:]|$)', 1, level, null, 1 )
您可以将 regexp_substr()
和 regexp_count()
与 connect by level<...
表达式组合使用:
with t as
(
select 100 as id, 'python java' as src from dual
)
select id, level as lvl, regexp_substr(src, '[^[:space:]]+',1,level) as token
from t
connect by level<= regexp_count(src,'[[:space:]]')+1
and prior id = id
and prior sys_guid() is not null;