I need to get the current year from the oracle db. For an example I need to return 2017 as the answer for the current year as a number type. I tried using following way.
select to_Number(sysdate, 'YYYY') from student s
But it not works. So what is the easiest way?
You need to_char instead of to_number
select to_char(sysdate, 'YYYY') from student;
That give a string though. you could apply to_number on it further to convert into number.
select to_number(to_char(sysdate, 'YYYY')) from student;
But there is better method using extract:
select extract(year from sysdate) from student;
Use extract
select extract(year from sysdate)
from dual;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With