我对您在示例中提供的日期范围有点困惑,因为每个范围的开始日期是 2013 年的星期日,但您将 2012 年显示为年份。我将假设 2012 是一个错字。
这能得到你想要的吗?
select
case
when trunc(sysdate) between start_date and end_date
then to_char(start_date + 1, 'DD-MON-YYYY')
else to_char(start_date, 'DD-MON-YYYY')
end
|| ' - ' ||
case
when trunc(sysdate) between start_date and end_date
then to_char(end_date - 1, 'DD-MON-YYYY')
else to_char(end_date, 'DD-MON-YYYY')
end date_range
from
(
select
next_day(trunc(sysdate - 7 + ((level - 1) * 7)), 'SUN') start_date,
next_day(trunc(sysdate) + ((level - 1) * 7), 'SAT') end_date
from dual
connect by level < 5
)
如果你只想要 4 周,那么你可以这样做
select
to_char(next_day(trunc(sysdate - 7 + ((level - 1) * 7)), 'SUN'), 'DD-MON-YYYY')
|| ' - ' ||
to_char(next_day(trunc(sysdate) + ((level - 1) * 7), 'SAT'), 'DD-MON-YYYY') date_range
from dual
connect by level < 5