YEAR(field) = '2011' in SQL Oracle

How I can use

YEAR(field) = '2011' in SQL Oracle ?

in Select Statements
egovernmentAsked:
Who is Participating?
 
sdstuberCommented:
where  extract(year from field) = 2011

or

where to_char(field,'yyyy') = '2011'

or

where field >= date '2011-01-01' and field < date '2012-01-01'


the third option is best as it will allow use of indexes

0
 
Muhammad Ahmad ImranDatabase DeveloperCommented:
no sure what you want ...

FEE> drop table temp;

Table dropped.

FEE> create table temp (a varchar2(4));

Table created.

FEE> insert into temp values ('2011');

1 row created.

FEE> select * from temp;

A
----
2011

FEE> select to_date(a,'yyyy') from temp;

TO_DATE(A
---------
01-JAN-11

FEE>
0
 
egovernmentAuthor Commented:
Hi leoahmad

For example I have a date in a Date field like

10/12/2011 in field fld_Birthday

I want to select who birthday in 2011 only

How that by SQL statemant ?
0
Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

 
Muhammad Ahmad ImranDatabase DeveloperCommented:
you mean you want birthdays of those who are in 2011 only.

select * from YourTable
where fld_birthday like '%2011';

should do that
0
 
egovernmentAuthor Commented:
hI leoahmad

I used
select * from YourTable
where fld_birthday like '%2011';

but return 0 rows

but there record include 2011

fld_Birthday is date not string
0
 
sdstuberCommented:
you could use
to_date('2011-01-01','yyyy-mm-dd')  
to_date('2012-01-01','yyyy-mm-dd')

 instead of the ansi date literals in the last option also
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.