Reputation: 1809
contains(columnname, 'ABC')=0
this means search for the data which doesn't contain word 'ABC'
contains(columnname, 'ABC and XYZ')=0
contains(columnname, 'ABC or XYZ')=0
what do these 2 sql mean? I tested them, there's no syntax error, but they didn't work as I expected, the 'and' seems like an 'or', and 'or' seems like an 'and', could anyone help to explain this? all doc found in google are for contains()>0, those're not what I need.
thanks in advance.
Upvotes: 1
Views: 17321
Reputation: 16905
According to oracle documentation, the contains
function :
returns a relevance score for every row selected
If you ask for
contains(columnname, 'ABC')=0
You actually ask for a score of 0
which means: columnname doesn't contain 'ABC'
According to the docs:
In an AND query, the score returned is the score of the lowest query term
In an OR query, the score returned is the score for the highest query term
So if you ask for:
contains(columnname, 'ABC and XYZ')=0
then if either 'ABC' or 'XYZ' has a score of 0
it will have the lowest score and that's what you'll get from the function, so you're actually asking for: columnname doesn't contain 'ABC' or 'XYZ' (at least one of them).
Same thing for the or
-
contains(columnname, 'ABC or XYZ')=0
only if both 'ABC' and 'XYZ' have the score of 0
the function will return 0
, so you're actually asking for: columnname doesn't contain 'ABC' and 'XYZ' (both of them).
IMHO, this behaviour is correct since it meets De-Moragan's Laws
Upvotes: 5