获取Oracle的蟾蜍的执行ID数量



请帮助提取针对相应ID的执行数数据例如我的temp1表具有ID和DT的数据,其中以下面的形式给出ID:

sngl〜27321〜subm〜 28867 _17227〜20170815.CSV.20170815113439sngl〜27321〜sump〜 28867 _17227〜20170815.CSV.20170815113439sngl〜27321〜subm〜 29329 _17227〜20170815.CSV.20170815113439

我需要以下结果:

ID执行号码28867 229329 1

查询如下:

select count(A.DT)
from temp1 a
where  A.id like '%28867%' 
and A.DT >= to_date( '01-Aug-2017','dd-MON-yyyy')
and A.DT < to_date('01-Sep-2017','dd-MON-yyyy')

我面临的问题是使用类似运算符从ID列中提取ID。

请帮助我在 toad中检索结果

您可以使用regexp_replace函数,或者可以使用substr和instr函数的组合来从字符串中提取此数字。


后者比Regexp_replace中的模式匹配快,因此,如果有一张巨大的字符串表,我将使用第二个选项。

SUBM~ substring 始终是,这应该有效:

With my_data as (
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' as str from dual union all
select 'SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439' from dual union all 
select 'SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439' from dual
)
SELECT
       regexp_replace( str, '.*SUBM~(d+).*', '1' ) as x,
       substr( str, 
               instr( str, 'SUBM~' ) + length('SUBM~'),
               instr( str, '_', instr( str, 'SUBM~' ) )
                - instr( str, 'SUBM~' ) 
                - length('SUBM~')
             ) as y
FROM My_data;

|     X |     Y |
|-------|-------|
| 28867 | 28867 |
| 28867 | 28867 |
| 29329 | 29329 |

最新更新