How do I get the current year using SQL on Oracle? How do I get the current year using SQL on Oracle? oracle oracle

How do I get the current year using SQL on Oracle?


Using to_char:

select to_char(sysdate, 'YYYY') from dual;

In your example you can use something like:

BETWEEN trunc(sysdate, 'YEAR')     AND add_months(trunc(sysdate, 'YEAR'), 12)-1/24/60/60;

The comparison values are exactly what you request:

select trunc(sysdate, 'YEAR') begin_year     , add_months(trunc(sysdate, 'YEAR'), 12)-1/24/60/60 last_second_yearfrom dual;BEGIN_YEAR  LAST_SECOND_YEAR----------- ----------------01/01/2009  31/12/2009


Another option is:

SELECT *  FROM TABLE WHERE EXTRACT( YEAR FROM date_field) = EXTRACT(YEAR FROM sysdate) 


Use extract(datetime) function it's so easy, simple.

It returns year, month, day, minute, second

Example:

select extract(year from sysdate) from dual;