简体   繁体   English

Oracle SQL自定义通配符

[英]Oracle SQL Custom Wildcards

I'm trying to find all that match a certain fingerprint, but Oracle's wildcards aren't terribly precise. 我试图找到所有匹配某个指纹的东西,但Oracle的通配符不是非常精确。

That fingerprint would be: WHERE symbol LIKE '%_####@' ESCAPE '\\' 该指纹将是:WHERE符号LIKE'%_ #### @'ESCAPE'\\'

Where it doesn't matter what comes before (the % wildcard) 前面的内容无关紧要(%通配符)
Next is an underscore (escaped with '\\') 接下来是下划线(用'\\'转义)
Then four numerals (#) 然后四个数字(#)
and finally a character AZ (@) 最后是一个角色AZ(@)

I've found some stuff using the translate function but I haven't been able to make it work. 我发现了一些使用translate函数的东西,但是我还没能使它工作。 Right now I'm investigating regular expressions but I've never used them before. 现在我正在调查正则表达式,但我以前从未使用它们。 I'm trying to understand what they are and how they would work to solve my problem. 我试图了解它们是什么以及它们如何解决我的问题。

It sounds like you want to be using regular expressions, not a LIKE. 听起来你想要使用正则表达式而不是LIKE。 Your "fingerprint" would appear to be captured by the regular expression [_][[:digit:]]{4}[AZ] so you can use regexp_instr to determine if the fingerprint is present (and what position in the string it is). 您的“指纹”似乎是由正则表达式[_][[:digit:]]{4}[AZ] regexp_instr [_][[:digit:]]{4}[AZ] regexp_instr ,因此您可以使用regexp_instr来确定指纹是否存在(以及字符串中的位置是什么) )。 In this case, the string '_1234B' is the fingerprint in the first string and that starts at position 7 在这种情况下,字符串'_1234B'是第一个字符串中的指纹,从位置7开始

SQL> ed
Wrote file afiedt.buf

  1  with x as (
  2    select 'sb1234_1234Bdelta' str from dual union all
  3    select 'no match' from dual
  4  )
  5  select str,
  6         regexp_instr( str, '[_][[:digit:]]{4}[A-Z]' )
  7    from x
  8*  where regexp_instr( str, '[_][[:digit:]]{4}[A-Z]' ) > 0
SQL> /

STR               REGEXP_INSTR(STR,'[_][[:DIGIT:]]{4}[A-Z]')
----------------- ------------------------------------------
sb1234_1234Bdelta                                          7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM