Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

REGEXP_LIKE help - escaping the hyphen

616610Jan 8 2008 — edited Oct 13 2009
I need to match string that does not contain "dc-ba" - all are literal. It has to return true for all strings that is not "ab-cd".

The hypen is creating the problem. If hypen were not there:

select ('Matched') "Status" from dual where REGEXP_LIKE('def', '[^(^dcba$)]');
Matched
select ('Matched') "Status" from dual where REGEXP_LIKE('dcba', '[^(^dcba$)]');
no rows returned
Everything is as required to this point, but when I try to apply the same with hypen:

select ('Matched') "Status" from dual where REGEXP_LIKE('dc-ba', '[^(^dc-ba$)]');

Error: ORA-12728: Invalid range in regular expression

If I try to escape the hyphen:

select ('Matched') "Status" from dual where REGEXP_LIKE('dc-ba', '[^(^dc\-ba$)]');
Matched
Which sould not be the case. It shoudl match all string other than "dc-ba".

Am I doing something wrong?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2009
Added on Jan 8 2008
10 comments
6,703 views