1

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

它应该是 3 个字母,3 个数字,然后可能是一个字母或不是

我试过这个:

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

但它只返回第一次出现。

使用

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

也不起作用

有人有什么想法吗?

编辑:

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

select * 
from abc123 
where some_value = 'some_value'
4

2 回答 2

3

试试这个查询来打破 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
于 2016-08-03T09:26:26.573 回答
1

尝试在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
于 2016-08-03T09:37:21.813 回答