【问题标题】:Get the number of execution id wise in toad for oracle在 toad for oracle 中明智地获取执行 id 的数量
【发布时间】:2017-09-01 22:53:00
【问题描述】:

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

SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439 SNGL~27321~SUBM~28867_17227~20170815.CSV.20170815113439 SNGL~27321~SUBM~29329_17227~20170815.CSV.20170815113439

我需要如下结果:

执行的id号 28867 2 29329 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')

我面临的问题是使用l​​ike运算符从id列中提取id。

请帮助我在 TOAD FOR ORACLE

中检索结果

【问题讨论】:

    标签: plsql oracle-sqldeveloper toad


    【解决方案1】:

    您可以使用REGEXP_REPLACE 函数或SUBSTRINSTR 函数的组合从字符串中提取此数字。

    后者比 REGEXP_REPLACE 中的模式匹配要快,所以如果有一个巨大的字符串表,我会使用第二个选项。

    假设 SUBM~ 子字符串 总是 在数字之前,这应该有效:

    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 |
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多