Oracle regexp_substr - 查找并提取列中的所有事件

Oracle regexp_substr - Find and extract all occurances in a column

我正在使用 Oracle 数据库,我正在尝试查找并提取字符串中与特定模式匹配的所有事件...

应该是 3 个字母,3 个数字,然后可能是字母也可能不是

我试过这个:

SELECT REGEXP_SUBSTR(my_column, '[A-Za-z]{3}(\d)(\d)(\d)') AS values 
FROM my_table

但它只是 returns 第一次出现。

使用

REGEXP_SUBSTR(my_column, '[A-Za-z]{3}(\d)(\d)(\d)', 0, 0, 'i')

也不行

有人有什么想法吗?

编辑:

我正在尝试从 PLSQL 文件中提取它。所以它非常像 SQL 查询

select * 
from abc123 
where some_value = 'some_value'

试试这个查询来打破 ABC123CDE456FGHI789 序列

with mine as (select 'ABC123CDE456FGH789' hello from dual) 
select regexp_substr(hello, '[A-Za-z]{3}(\d){3}', 1, level) STR from mine
connect by regexp_substr(hello, '[A-Za-z]{3}(\d){3}', 1, level) is not null

输出

ABC123
CDE456
GHI789

为了获得特定的位置然后你想使用

select regexp_substr('ABC123CDE456FGH789', '[A-Za-z]{3}(\d){3}', 1, i) STR from dual

根据位置更改 i 值

select regexp_substr('ABC123CDE456FGH789', '[A-Za-z]{3}(\d){3}', 1, 1) STR from dual

输出:

ABC123

尝试获取1.2.3中的号码(假设是一个国家的域名)

SELECT str,level,REGEXP_SUBSTR(str, '[0-9]', 1, LEVEL) AS substr
FROM (
SELECT country_domain str from country where regexp_like(country_domain, '[0-9]')
)
CONNECT BY LEVEL <= REGEXP_count(str, '[0-9]');

输出

STR    LEVEL SUBSTR
1.2.3   1     1
1.2.3   2     2
1.2.3   3     3