3

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

I want to create a function that get this date check it for not null and then change it to yyyy/mm/dd format

but the problem is that oracle doesn't accept dd-MMM-yy formate date as a input parameter and it say : Please Use yyyy-MM-dd date format !!!

how can I first change dd-MMM-yy formate to yyyy-MM-dd so oracle accept it as input then change it to yyyy/mm/dd

7
  • What is the exact error? How are you inputing the data?
    – Mureinik
    Feb 3, 2015 at 12:24
  • Also in oracle MMM is MON when dealing with date format strings.
    – Asheliahut
    Feb 3, 2015 at 12:27
  • 6
    "I have a date field in a table that contains date in dd-MMM-yy format" - no you don't. Dates don't have "a format". Any format you see is applied by the SQL client you use. To change the formatting of the output, configure your SQL client appropriately.
    – user330315
    Feb 3, 2015 at 12:31
  • 1
    What is the datatype of your field? Is it DATE or VARCHAR2? If the former, then you don't need to do anything, as you don't control the way that Oracle stores DATE values (you can only control how you view them and how you pass dates-as-a-string into the field/variable). As others have requested, we need more information. What have you written so far. What is your table definition? What is the exact error message?
    – Boneist
    Feb 3, 2015 at 12:42
  • 1
    @Lalit I am trying to solve the problem , tnx for your complete answer
    – OmiD
    Feb 3, 2015 at 14:56

1 Answer 1

12

: 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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.