Mvz
Mvz

Reputation: 507

Oracle - Query that only checks for a certain year

Test 1

Date        id
01-02-2011  1
01-08-2011  1
01-04-2012  1
01-02-2013  1
01-02-2015  1
01-05-2015  1
01-06-2015  1

I want a query that only checks for the year like

select Date, id from Test1 where Date like 2015;

So the output is:

Date        id
01-02-2015  1
01-05-2015  1
01-06-2015  1

Upvotes: 0

Views: 33

Answers (2)

Madhivanan
Madhivanan

Reputation: 13700

If the date column has index, the best way I can think of is

select * 
from test1
where Date >= to_date('01-JAN-15','DD-MON-YY') and Date < to_date('01-JAN-16','DD-MON-YY') 

Upvotes: 3

davegreen100
davegreen100

Reputation: 2115

select * 
from test1
where to_char(datecol,'yyyy')= '2015'

Upvotes: 3

Related Questions