Question

There's an Oracle database with a bunch of entries where there are '*' before, in the middle, and at the end of the string. I'm performing some data analysis and want to see how many entries that exist that have * somewhere in the middle of the string with at least one char before and after. However according to http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_re.htm * is a metacharacter, but I'm not sure how to make it be treated as a literal despite looking the the documentation. I've tried [*], (*), \*, but all have resulted in ORA-00920: invalid relational operator

SELECT COUNT(*) FROM myTable mT WHERE REGEXP_LIKE (mT.myCol, '.[*].');
Was it helpful?

Solution

Seems to work fine for me:

> drop table tabx
table TABX dropped.
> create table tabx
(
val varchar2(10)
)
table TABX created.
> insert into tabx values ('AB*CD')
1 rows inserted.
> insert into tabx values ('A*B')
1 rows inserted.
> insert into tabx values ('DEF')
1 rows inserted.
> commit
committed.
> SELECT * FROM tabx x WHERE REGEXP_LIKE (x.val, '.[*].')
VAL      
----------
AB*CD      
A*B    

Your error may be coming from elsewhere.

OTHER TIPS

Another way to format the query is as follows:

REGEXP_LIKE(mT.myCol, '.*\*.*')

But I also don't think that the issue is with the regex.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top