An Oracle DATE
column contains a date and a time. The LIKE
condition is only for VARCHAR
columns. If applied to other data types Oracle implicitly converts that to a varchar (using rules depending on the current client settings).
So you might have rows with e.g. 2013-01-25 17:42:01
, however the string constant '25-JAN-13'
is (most probably) converted to: 2013-01-25 00:00:00
and thus the =
comparison doesn't work.
To find all rows for a specific day use trunc()
and a proper date literal. Don't rely on the evil implicit data type conversion to specify date values.
Use trunc()
to set the time part of a DATE
value to 00:00:00
:
I prefer ANSI SQL date literals:
select count(*)
from CI_TXN_HEADER
where trunc(TXN_HEADER_DTTM) = DATE '2013-01-25';
You can also use Oracle's to_date:
select count(*)
from CI_TXN_HEADER
where trunc(TXN_HEADER_DTTM) = to_date('2013-01-25', 'yyyy-mm-dd');
Note that Oracle can't use an index on TXN_HEADER_DTT
, so if performance is critical use a range query:
select count(*)
from CI_TXN_HEADER
where TXN_HEADER_DTTM >= DATE '2013-01-25'
and TXN_HEADER_DTTM < DATE '2013-01-25' + 1;