Ok, so I want to convert a date value to properly format my date for comparison, however, will converting my “DATE” data type to char affect indexing when comparing on that field? Can I resolve this by doing to_date(tochar())? Any advice on this would be greatly appreciated Thanks!
EDIT – Sorry for the lack of specifics…. basically I need to eliminate the time stamp from my date, I used the following and it appears to work TO_DATE(TO_CHAR, ‘YYYY-MM-DD’),’YYYY-MM-DD’), mind you I don’t know if this is good practice or not, but at least (or so I think) now it’s comparing a DATE against a DATE, and not a string.
If you are doing a comparison, you should not be converting the date to a string. You should be comparing to another date. Otherwise, Oracle won’t be able to use a non function-based index on the date column.
In general, that is, you’re much better off coding
rather than
Of course, if your bind variable can be a
DATErather than aVARCHAR2, that’s even better because then you don’t have to do any data type conversion and the optimizer has a much easier time of estimating cardinalities.If you are trying to do some manipulation of the date– for example, if you want to compare the day portion while omitting the time portion of the date– you may want to use function-based indexes. For example, if you wanted to find all the rows that were created some time today
you could either create a function-based index on the date column
or you could rewrite the query to do something like