Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Dates
People have explained why your query is returning unexpected results.
Here is how to correctly write your query.
Correct version:
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS >= to_date ('2004/06/25', 'YYYY/MM/DD') and NC_DATE_CLS < to_date ('2004/06/26', 'YYYY/MM/DD') ;
Or
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS between to_date ('2004/06/25', 'YYYY/MM/DD')
and to_date ('2004/06/26 23:59:59', 'YYYY/MM/DDHH24:MI:SS') ;
Note that if you write your query as
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS between to_date ('2004/06/25', 'YYYY/MM/DD')
and to_date ('2004/06/26', 'YYYY/MM/DD') ;
You will get different results - this will also include all records having the date/time Midnight 26 June 2004.
-----Original Message-----
From: Oracle
Can any please explain the reason for the differing results in the
folowing
queries
1)
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS LIKE
'25-JUN-04'
NCSN NC_DATE_CLS
--------- --------- 3298 25-JUN-04 3299 25-JUN-04
2)
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS =
'25-JUN-04'
no rows selected
3)
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS between
'25-JUN-04' AND '25-JUN-04';
no rows selected
4)
SELECT NCSN, NC_DATE_CLS FROM NONCONFORM WHERE NC_DATE_CLS between
'24-JUN-04' AND '26-JUN-04'
NCSN NC_DATE_CLS
--------- --------- 3298 25-JUN-04 3299 25-JUN-04
Table nonconform....columns....NCSN NUMBER, NC_DATE_CLS DATE...... Oracle 8.1.7
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html -----------------------------------------------------------------Received on Fri Jun 25 2004 - 11:51:17 CDT