I am currently using the following query to get all the inspections done on june 2010:
select inspections.name
from inspections
where
to_char(inspections.i
select inspections.name
from inspections
where
extract(year from inspections.insp_date) = 2010 and
extract(month from inspections.insp_date) = 6;
Another option would be
SELECT inspections.name
FROM inspections
WHERE TRUNC( inspections.insp_date, 'MM' ) = date '2010-06-01';
From an efficiency perspective
I like to use range comparison when possible since this can be used for index-scan by the optimizer:
select inspections.name
from inspections
where inspections.date >= DATE '2010-06-01'
and inspections.date < DATE '2010-07-01'
I agree with Vincent's answer, but for completeness you could simplify yours to:
select inspections.name
from inspections
where
to_char(inspections.insp_date, 'YYYYMM') = '201006';
That could even use an index, provided the index were:
create index x on inspections (to_char(insp_date, 'YYYYMM'));