Search code examples
oracle-databasedate-conversion

In Oracle, why does this return March 1st?


In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know why?

SELECT TO_DATE( '2010' ,'yyyy' ) AS STRANGE_YEAR_RESULT
FROM DUAL

I've tried on Oracle 10g and 11g.


Solution

  • Oracle needs a complete DateTime in its Date type value field, thus making it take the first day of the current month, I would guess, since you required no other information than the year. Remember that you always need to cast through TO_DATE() and TO_CHAR() dates in Oracle. Assuming so, Oracle "knows" that you will get the information required.