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

落爺英雄遲暮 提交于 2019-12-11 02:17:40

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/29263586/how-to-convert-yyyymmdd-to-dd-mon-yyyy-in-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!