Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle to_char bug

I don't know if it's a bug or what, but when I try to format the Day of the week in a certain way with the to_char function in Oracle, SQL Plus give me this error : ORA-01821: date format not recognized

Here's the line that cause a problem

SELECT TO_CHAR(sysdate,'dsp') from dual;

So d is of 'Day of the week' and sp is for spell. This line should print five because we are thursday.

It's weird because this next line worked

SELECT TO_CHAR(sysdate,'ddsp') from dual;

dd is for 'Day of the month' so sql plus printed twenty-nine without any problem!!

Can someone tell me why this line is not working?

Thanks..

like image 325
Joel Avatar asked Sep 29 '11 17:09

Joel


1 Answers

If you must make this work, here's an ugly workaround:

SELECT to_char(to_date(to_char(SYSDATE,'d'),'j'),'jsp') FROM dual;

Looks like a bug to me...

like image 54
DCookie Avatar answered Sep 28 '22 11:09

DCookie