简体   繁体   中英

Oracle SQL Custom Wildcards

I'm trying to find all that match a certain fingerprint, but Oracle's wildcards aren't terribly precise.

That fingerprint would be: WHERE symbol 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 (@)

I've found some stuff using the translate function but I haven't been able to make it work. 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. 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). In this case, the string '_1234B' is the fingerprint in the first string and that starts at position 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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