如何在oracle中将YYYYMMDD转换为DD-Mon-YYYY?

时间:2015-03-25 18:24:36

标签: sql oracle oracle11g

我正在尝试将日期从 YYYYMMDD 转换为Oracle中的 DD-Mon-YYYY ,但to_charto_Date无效。你能告诉我吗?

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

我收到一条错误消息:- ORA-01861: literal does not match format string

1 个答案:

答案 0 :(得分:4)

使用to_charto_date的这种组合:

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

你的错误是,你使用了错误的日期模式。此外,建议添加'',但在这种情况下,它可以不使用它们。

检查this Fiddle