Oracle Select Where String (sans hyphens) is like String

I need to figure out how to apply a regular expression to a query so that the string passed in is compared, dbData LIKE (%passedInString%), to the string in the database, but where the stings are both devoid of hyphens.

Example of what is in the database: DR-9JPE-P-77-7733
Examples of what might be passed in that would return a match: 7777333, P77, 9JPEP-77, etc.

Is it even possible?  Help me out!  :)  And thanks in advance!

A basic, albeit wrong version, of what I am trying to do:
SELECT *
FROM aTable
WHERE REGEXP(INDATABASE) LIKE (%REGEXP(PASSEDIN)%)

Open in new window

LVL 1
brianmfallsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Given that requirement I would replace all dashes with nothing and do an instr:
select * from table where instr(replace(passedin,'-'),replace(INDATABASE,'-')) > 0;

If there is an index on INDATABASE then it will be ignored.  If so, we can try some alternatives.  Easiest is a function-based index.
brianmfallsAuthor Commented:
So, to be literal, would it look like this?

SELECT *
FROM tableName
WHERE instr(replace('9JPEP-77','-'),replace(columnName,'-')) > 0;

Open in new window

slightwv (䄆 Netminder) Commented:
Sorry.  I had it backwards.

Try this:
SELECT *
FROM tableName
WHERE instr(replace(columnName,'-'),replace('9JPEP-77','-')) > 0;

Set up a quick test case:
select case when  instr(replace('DR-9JPE-P-77-7733','-'),replace('9JPEP-77','-')) > 0 then 'Found' else 'Not Found' end from dual;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brianmfallsAuthor Commented:
Perfect.  Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.