Formatting DATE in oracle

: Please Use yyyy-MM-dd date format !!!

That is no way related to an Oracle error.

I have a date field in a table that contains date in dd-MMM-yy format .

No, you are confused. Oracle does not store dates in the format you see. It stores it internally in 7 bytes with each byte storing different components of the datetime value.

Byte    Description
----    -------------------------------------------------
1       Century value but before storing it add 100 to it
2       Year and 100 is added to it before storing
3       Month
4       Day of the month
5       Hours but add 1 before storing it
6       Minutes but add 1 before storing it
7       Seconds but add 1 before storing it

If you want to display, use TO_CHAR with proper FORMAT MODEL.

While inserting, use TO_DATE with proper FORMAT MODEL.

What you see as a format by default, is your locale specific NLS settings.

SQL> select parameter, value from v$nls_parameters where parameter="NLS_DATE_FORMAT";

PARAMETER       VALUE
--------------- ----------------------------------------------------------------
NLS_DATE_FORMAT DD-MON-RR

SQL> select sysdate from dual;

SYSDATE
---------
03-FEB-15

SQL> select to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'MM
-------------------
02/03/2015 17:59:42

SQL>

Update Regarding MMM format.

By MMM if you mean the month name up to three characters, then use MON.

Leave a Comment