Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用Oracle REGEXP_SUBSTR提取由下划线分隔的大写数据_Sql_Oracle_Regexp Substr - Fatal编程技术网

Sql 使用Oracle REGEXP_SUBSTR提取由下划线分隔的大写数据

Sql 使用Oracle REGEXP_SUBSTR提取由下划线分隔的大写数据,sql,oracle,regexp-substr,Sql,Oracle,Regexp Substr,样本列数据: Failure on table TOLL_USR_TRXN_HISTORY: Failure on table DOCUMENT_IMAGES: Error in CREATE_ACC_STATEMENT() [line 16] 我正在寻找一种只提取用下划线分隔的大写单词表名的方法。我想要整个表名,最大值是3个下划线,最小值是1个下划线。我想忽略initcap中的任何大写字母。您可以将其用于每个替换的单独行 在以下情况下,TOLL_USR_TRXN_历史记录表出现故障 从您的文

样本列数据:

Failure on table TOLL_USR_TRXN_HISTORY:
Failure on table DOCUMENT_IMAGES:
Error in CREATE_ACC_STATEMENT() [line 16]
我正在寻找一种只提取用下划线分隔的大写单词表名的方法。我想要整个表名,最大值是3个下划线,最小值是1个下划线。我想忽略initcap中的任何大写字母。

您可以将其用于每个替换的单独行 在以下情况下,TOLL_USR_TRXN_历史记录表出现故障 从您的文字:

select regexp_replace(q.word, '[^a-zA-Z0-9_]+', '') as word 
  from
(
  select substr(str,nvl(lag(spc) over (order by lvl),1)+1*sign(lvl-1),
         abs(decode(spc,0,length(str),spc)-nvl(lag(spc) over (order by lvl),1))) word, 
         nvl(lag(spc) over (order by lvl),1) lg
    from
  (
    with tab as
      ( select 'Failure on table TOLL_USR_TRXN_HISTORY' str from dual )
        select instr(str,' ',1,level) spc, str, level lvl
          from tab 
       connect by level <= 10
  )
) q
where lg > 0
    and upper(regexp_replace(q.word, '[^a-zA-Z0-9_]+', '')) 
      = regexp_replace(q.word, '[^a-zA-Z0-9_]+', '')
  and ( nvl(length(regexp_substr(q.word,'_',1,1)),0) 
      + nvl(length(regexp_substr(q.word,'_',1,2)),0) 
      + nvl(length(regexp_substr(q.word,'_',1,3)),0)) > 0
  and   nvl(length(regexp_substr(q.word,'_',1,4)),0)  = 0;    

从下面的错误消息中仅获取表名的另一种方法,只有当表名以上述方式结束时,下面的查询才会工作

with t as( select 'Failure on table TOLL_USR_TRXN_HISTORY:' as data from dual)
SELECT RTRIM(substr(data,instr(data,' ',-1)+1),':') from t
所有邮件的新查询:

 select  replace (replace ( 'Failure on table TOLL_USR_TRXN_HISTORY:
Failure on table DOCUMENT_IMAGES:' , 'Failure on table', ' ' ),':',' ') from dual
你可以用


该模式表示查找带有大写字母或下划线的子字符串,至少3个字符长。1,1表示从第一个位置开始并返回第一个匹配。“c”使搜索区分大小写。

对于您的数据,是否应该提取CREATE_ACC_语句?如果字符串为“表上的故障\u USR\u TRXN\u历史记录\u USR\u TRXN\u HISTORY 2:”。。?然后,仅返回TOLL_USR_TRXN_HISTORY2。对于所有大写字母和下划线都没有过滤器。只返回句子的最后一个单词是的Barbaro。。。这行不通。这将只选择最后一个单词我已更新查询以处理多个消息…因为错误消息很常见,所以我使用此查询。。。。但我看到你的问题是可怕的,无论它可以:-谢谢,这正是我想要的。
select regexp_substr(str, '[A-Z_]{3,}', 1, 1, 'c')
from (select 'Failure on table TOLL_USR_TRXN_HISTORY' as str from dual) x;