Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why can not I format a sql date?

In the following code, I can not convert the date to the given format. why?

select sysdate,to_char('09/21/1990','ddth "of" mm yyyy') as formated
from emp;

error message:

ORA-01722: invalid number

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The to_char function is to convert a DATE type to a string. Your date parameter is already a string. If you really are executing the query with a string literal, you would have to convert it to a DATE type first, then to the string format you need, like this

select sysdate,
       to_char(to_date('09/21/1990','MM/DD/YYYY'),'ddth "of" mm yyyy')  as formated
from emp;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading