我为此感到抱歉,但我之前的问题没有正确构建,因此创建了另一个帖子。
我的问题类似于以下问题: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:14582643282111
我需要编写内部查询,它将为我提供两个日期范围与外部查询之间的日期列表。
我的内部查询返回以下两行:
SELECT request.REQ_DATE, request.DUE_DATE FROM myTable where id = 100
REQ_DATE DUE_DATE
3/19/2013 3/21/2013
3/8/2013 3/8/2013
所以我需要内部查询,它会将以下日期返回到外部查询:
3/19/2013
3/20/2013
3/21/2013
3/8/2013
上面帖子中的答案有硬编码的开始日期和结束日期,在我的情况下,它来自其他表格。所以我试图写这样的查询不起作用:
Select * from outerTable where my_date in
(
select to_date(r.REQ_DATE) + rownum -1 from all_objects,
(
SELECT REQ_DATE, DUE_DATE
FROM myTable where id = 100
) r
where rownum <= to_date(r.DUE_DATE,'dd-mon-yyyy')-to_date(r.REQ_DATE,'dd-mon-yyyy')+1;
)
答案 0 :(得分:0)
with
T_from_to as (
select
trunc(REQ_DATE) as d_from,
trunc(DUE_DATE) as d_to
FROM myTable
where id = 100
),
T_seq as (
select level-1 as delta
from dual
connect by level-1 <= (select max(d_to-d_from) from T_from_to)
)
select distinct d_from + delta
from T_from_to, T_seq
where d_from + delta <= d_to
order by 1