Avinash Ganesh
Avinash Ganesh

Reputation: 453

how to convert YYYYMMDD to DD-Mon-YYYY in oracle?

I am trying to convert the date from YYYYMMDD to DD-Mon-YYYY in Oracle, but to_char or to_Date is not working. Can you please advise?

select to_date(20150324,'DD-Mon-YY') from dual; select to_char(20150324,'DD-Mon-YY') from dual;

I get an error message saying: - ORA-01861: literal does not match format string

Upvotes: 4

Views: 48360

Answers (1)

Trinimon
Trinimon

Reputation: 13957

Use this combination of to_char and to_date:

select to_char (to_date('20150324','YYYYMMDD'), 'DD-Mon-YY') from dual;

Your mistake was, that you used the wrong date pattern. Additionally it's recommended to add'', though it worked without them in this case.

Check this Fiddle.

Upvotes: 8

Related Questions