Question: How to I compare dates in
Oracle?
Answer: In Oracle, dates have a DATE
internal format and comparing DATES should be with matching data
types, preferably a DATE to DATE datatype. If you avoid this
data type mismatch and convert your text with the to_date
function it is easy to compare dates in Oracle;
where my_date_col > to_date(2010-10-12,YYYY-MM-DD);
Below we compare to DATE in character format:
where to_char(my_char_col) > 2015-10-12
Comparing dates the wrong way
These Oracle date comparisons works, but no index cannot be used
because date2 is invalidated with the trunc function (unless you
create a function-based index on trunc(date2,'YYYY:MM').
where to_char(DATE1,'YYYY:MM')
>= to_char(DATE2,'YYYY:MM')
where trunc(date1,'mm') >=
trunc(date2,'mm');
|
|
Get the Complete
Oracle SQL Tuning Information
The landmark book
"Advanced Oracle
SQL Tuning The Definitive Reference" is
filled with valuable information on Oracle SQL Tuning.
This book includes scripts and tools to hypercharge Oracle 11g
performance and you can
buy it
for 30% off directly from the publisher.
|