I'm running this SQL code.

select  to_char(to_date('14-05-13','yyyy-mm-dd'),'yyyy') from dual;

I don't know why oracle returns 0014 for me.

Could someone help me?

有帮助吗?

解决方案 2

you can replace YYYY to RRRR

select to_char(to_date('14-05-13','rrrr-mm-dd'),'rrrr') from dual;

其他提示

You are giving it "yyyy-mm-dd" for a date format, but you are giving it a date of "14-05-13". So, you are literally telling it that the date is 5/13/0014.

Try either:

select to_char(to_date('14-05-13','yy-mm-dd'),'yyyy') from dual

or preferably:

select to_char(to_date('2014-05-13','yyyy-mm-dd'),'yyyy') from dual;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top