我有一个表,该表有2列:ID和JOB_Description(Text)。 我想编写一个oracle SQL以提取其中的所有子字符串 与常规模式匹配的描述列。
但是,我已经学会了如何使用下面的SQL从字符串中提取匹配的子字符串,但是我不知道一次在上述表(列:JOB_Description)上一次对所有数据使用下面的SQL。
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}');
答案 0 :(得分:1)
您可以尝试此查询。
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
对后两行的很好解释