select * from tableName where "value" >= TO_DATE('2012-05-12', 'yyyy-mm-dd') AND "value" <= TO_DATE('2012-07-12','yyyy-mm-dd');
-- ^^^^^
You have an implicit type conversion here using you NLS date format, as, according to the documentation (same link):
When comparing a character value with a DATE value, Oracle converts the character data to DATE.
The quick fix is to write:
select * from tableName where TO_DATE("value", 'yyyy-mm-dd') >= TO_DATE('2012-05-12', 'yyyy-mm-dd')
AND TO_DATE("value", 'yyyy-mm-dd') <= TO_DATE('2012-07-12','yyyy-mm-dd');
But, as your date format is lexicography comparable, you might write that instead:
select * from tableName where "value" >= '2012-05-12'
AND "value" <= '2012-07-12';
However, I would strongly suggest you to fix your data to ensure that you use the proper DATE
type for your column. This will avoid a bunch of possible bugs and problems like this one.
As suggested by Falco in a comment below, "if you cannot change the column type to DATE
, you should probably create a function-based Index for the TO_DATE(...)
Value to get fast query times".