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:
- having hidden character behind
z(i.e.:'z'||chr(0)||'oco') - or using locale such
z-something considered different letter, collation order outside of given range. don't know if such locale exists, example, in welch,llconsidered single letter should sorted after plainl. see http://en.wikipedia.org/wiki/alphabetical_order#language-specific_conventions - or having homogplyphs such
0,𐒠orОinstead ofoin data.
Comments
Post a Comment