Oracle select all rows using the contains keyword

5.8k Views Asked by At

I'm looking for a character that I can use in an Oracle contains to get ALL results.

If I search for the string "test" in a title column I use this statement:

select * 
from my_table 
where contains (title, 
    '<query><textquery grammar="CTXCAT">test</textquery></query>') > 0

With this statement I get the rows which have the "test"-string included in title-column.

BUT: Is there any way to use contains and select ALL rows?

2

There are 2 best solutions below

2
On

The documentation says wildcards with the Oracle Text CONTAINS() predicate are % and _ just like the LIKE predicate.

Does the following work? I don't have an instance of Oracle handy to test.

select * 
from my_table 
where contains (title, 
    '<query><textquery grammar="CTXCAT">%</textquery></query>') > 0
3
On

Would this work for you?

select * from my_table
where title like 
    '<query><textquery grammar="CTXCAT">%</textquery></query>'

This uses the LIKE syntax and the % wildcard to achieve what I think you want.