oracle 从列中获取所有匹配的事件

oracle get all matched occurrences from a column

我有一个 table,它有 2 列:ID 和 JOB_Description(文本)。 我想写一个 oracle SQL 来提取 与常规模式匹配的描述列。

然而,我已经学会了如何从 SQL 以下的字符串中提取匹配的子字符串,但我不知道将 SQL 以下的所有数据一次应用于上述 table(列:JOB_Description).

SQL 从字符串中获取所有匹配项:

 SELECT REGEXP_SUBSTR(JOB_Description, '(ABC|DE)([[:digit:]]){5}', 1, LEVEL) AS substr
   FROM (
         select 'Please help to repair ABC12345, DE22222' as JOB_Description 
          from DUAL)
  CONNECT BY LEVEL <= REGEXP_COUNT(JOB_Description, '(ABC|DE)([[:digit:]]){5}');

您可以试试这个查询。

 with test as(
  select 'ABC12345, DE22222' as JOB_Description from DUAL union
  select 'Please help to repair ABC12345, DE22222' as JOB_Description from DUAL 
)
SELECT REGEXP_SUBSTR(JOB_Description, '(ABC|DE)([[:digit:]]){5}', 1, LEVEL) AS substr
FROM test
CONNECT BY LEVEL <= REGEXP_COUNT(JOB_Description, '(ABC|DE)([[:digit:]]){5}')
  AND PRIOR JOB_Description = JOB_Description
  AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL

结果:

ABC12345
DE22222
ABC12345
DE22222

可以找到最后两行的很好解释here