Database

(Oracle) Comparing Dates

steloflute 2013. 1. 4. 23:30

http://forums.devshed.com/oracle-development-96/comparing-dates-87728.html

 


SELECT count(*)
FROM sessions
where sess_date > to_date('2003-09-03', 'YYYY-MM-DD');

but this query does not:

SELECT count(*)
FROM sessions
where sess_date = to_date('2003-09-03', 'YYYY-MM-DD');

when I know the date does exist in the database. It's driving me mad.

 


I suspect that you would have better luck using:

select count(*)
from sessions
where to_char(sess_date, 'YYYY-MM-DD') = '2003-09-03';

As for why your second query doesn't work... well, the most likely problem is that sess_date has a time component that's not set to exactly midnight. I'd suggest using to_char rather than to_date, though, as it gives you a little better control over exactly what you're trying to compare.

Marty

 

'Database' 카테고리의 다른 글

(Oracle) table backup  (0) 2013.01.18
Oracle SQL Where clause to find date records older than 30 days  (0) 2013.01.16
(Oracle) delete 복구  (0) 2012.11.09
(Oracle) data pump 권한 주기  (0) 2012.11.05
(Oracle) Compressed Table  (0) 2012.10.31