SQL Language (MOSC)

MOSC Banner

Question on the precedence of AND OR operator

edited Oct 6, 2016 9:57AM in SQL Language (MOSC) 4 commentsAnswered

Dear experts,

I have this query which involved "AND" and "OR" operators. For the operation which are in bold, they return different results when I changed its order.

I have share the following scenario and their results. Could anyone please advise how could this happens? Thanks.

Work Fine: --23178 rows

------------------------------

select count(*)

  from test_table

  where 1=1

   AND (LAST_REPORT_TIME BETWEEN TO_DATE(:DATE_FROM,'DD-MON-YY') AND (TO_DATE(:DATE_TO,'DD-MON-YY') + 1))

  AND (EXCLUDE_FLAG = :EXCLUSIONS OR NVL(EXCLUDE_FLAG,'N') = 'N') ;

---------------------------------

Return 0 records:

------------------------------

select count(*)

  from test_table

  where 1=1

  AND (EXCLUDE_FLAG = :EXCLUSIONS OR NVL(EXCLUDE_FLAG,'N') = 'N')

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center