Oracle NOT BETWEEN for string comparison does not give same result as <= and >= -


using oracle 11gr2 expression edition. data looks following

ordertype --------- zoco zosa zost 

we trying find out records column not between range of values.

if run query <= , >= operators: select * table ordertype <= 'zaaa' or ordertype >= 'zzzz'; 0 results. this right answer.

however, if use not between: select * table ordertype not between 'zaaa' , 'zzzz'; , gives multiple hits.

my understanding both syntax should give same result not. missing? reason want use not between because lot of our existing code has syntax , not want change without understanding reasons.

thank you.


thanks posted. ran queries again , after fixing "or" in first query, results same. still have question of why oracle character sorting not recognizing expected, question difference between not between , <> false alarm. apologize confusion.

select * table ordertype <= 'zaaa' , ordertype >= 'zzzz'; 

no string can <= 'zaaa' and >= 'zzzz'. need use disjunction instead:

select * table ordertype < 'zaaa' or ordertype > 'zzzz'; 

btw, given between inclusive, not between exclusive


this common pitfall. have remember de morgan's laws:

not (a , b) same (not a) or (not b)

feel free experiment simple live example convince results quite coherent: http://sqlfiddle.com/#!4/d41d8/38326


that being said, way (i can see) string zoco not being between zaaa , zzzz be:


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -