无需使用 重复该created_date
列between
,即使查询继续利用该列上的索引(如果有),通过使用trunc(to_date('2012-09','yyyy-mm'),'Month')
该月的第一个日期和last_day(to_date('2012-09','yyyy-mm'))
最后一个日期。
with orders(order_number, created_date) as
(
select 1, date'2012-08-31' from dual union all
select 2, date'2012-09-01' from dual union all
select 3, date'2012-09-02' from dual union all
select 4, date'2012-09-29' from dual union all
select 5, date'2012-09-30' from dual union all
select 6, date'2012-10-01' from dual
),
param(month) as
(
select to_date('2012-09','yyyy-mm') from dual
)
select order_number, created_date
from orders
cross join param
where created_date between trunc(month,'Month')
and last_day(month);
ORDER_NUMBER CREATED_DATE
------------ ------------
2 01.09.2012
3 02.09.2012
4 29.09.2012
5 30.09.2012
Demo