Avatar of David VanZandt
David VanZandtFlag for United States of America asked on

Help requested with Oracle REGEXP_LIKE syntax

One of our senior developers asked the Oracle DBAs to execute this query, attached. Rather than doing fifteen full-table scans, I thought I'd try it with REGEXP_LIKE. Well, I'm looked at Oracle and other documentation for a good two hours without catching my error(s). I would appreciate a fresh pair of eyes, please. My most recent effort is

Select * from MYSCHEMA.CNSTR_NBR
   where REGEXP_LIKE(CNST_NR_ID, 'WF20(2|3|6)02[2-6]%')
   order by CNST_NR_ID desc;

Looking at the original script in the code snippet, the match pattern clearly shows four elements: the string WF20, character 5 has to be 2,3, or 6; a second string 02, and a final match on 2 through 6 inclusive. The trailing characters in the column should be ignored.  TIA for taking a look.


Select * from MYSCHEMA.CNSTR_NBR
   where CNST_NR_ID LIKE ('WF206022%')
      or CNST_NR_ID LIKE ('WF206023%')
      or CNST_NR_ID LIKE ('WF206024%')
      or CNST_NR_ID LIKE ('WF206025%')
     or CNST_NR_ID LIKE ('WF206026%')
     
      or CNST_NR_ID LIKE ('WF203022%')
      or CNST_NR_ID LIKE ('WF203023%')
      or CNST_NR_ID LIKE ('WF203024%')
      or CNST_NR_ID LIKE ('WF203025%')
     or CNST_NR_ID LIKE ('WF203026%')
     
      or CNST_NR_ID LIKE ('WF202022%')
      or CNST_NR_ID LIKE ('WF202023%')
      or CNST_NR_ID LIKE ('WF202024%')
      or CNST_NR_ID LIKE ('WF202025%')
     or CNST_NR_ID LIKE ('WF202026%')
    order by CNST_NR_ID desc;

Oracle Database

Avatar of undefined
Last Comment
Sean Stuber

8/22/2022 - Mon
Kent Olsen

Regular expressions are just a bit different than the syntax you're used to.

Instead of using '%', use '.*'.  In regular expressions that means match any character, any number of times (including zero).


ASKER CERTIFIED SOLUTION
Sean Stuber

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck