Caffeinated
Caffeinated

Reputation: 12484

What is the format, for inserting DATE values in Oracle SQL?

In Oracle SQL, I read that the default date format is 'YYYY-MON-DD'

But however, when I run this query:

  SELECT TO_CHAR
    (SYSDATE) "NOW"
    FROM DUAL;

It returns :

23-APR-15

I was expecting something like '2015-APR-23' though..

Why is that? thanks

See this question- Oracle's default date format is YYYY-MM-DD, WHY?

Upvotes: 1

Views: 187

Answers (1)

Justin Cave
Justin Cave

Reputation: 231691

The default date format is whatever is specified by your session's nls_date_format. You should never, ever write code that relies on the session's nls_date_format however, since that depends on things like the user's preference, their country and region, etc. You should be using explicit conversions and/or date literals (date 'yyyy-mm-dd') in your code rather than relying on implicit conversion. If you care about the format of the string that is returned, you'd need to provide an explicit format mask in your to_char call.

It appears that your session's nls_date_format is DD-MON-RR which is a common default for an English language install. Someone else's default may be YYYY-MON-DD. Someone else may have yet another default.

Upvotes: 5

Related Questions