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