Question on the precedence of AND OR operator
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')