Вопрос

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