首页 > 解决方案 > 如何在 oracle 中拆分以空格分隔的字符串并将每个单词添加到 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 在单独的行中。

标签: sqlregexoraclesplitregexp-substr

解决方案


您的正则表达式似乎有点困惑。我认为您想要更多类似的东西:

regexp_substr( src , '(.*?)([[:space:]0-9/:]|$)', 1, level, null, 1 )

db<>小提琴


推荐阅读