根据行日期Oracle从一个查询行中选择多行

时间:2013-07-03 07:20:13

标签: sql oracle

我有一个查询。我想为查询中的每一行选择多行,如下所示:

select process, fromdate, todate from
(
select 'A' as process, to_date('03.04.2013','dd.mm.yyyy') as fromdate, to_date('06.04.2013','dd.mm.yyyy') as todate
UNION
select 'B' as process, to_date('06.04.2013','dd.mm.yyyy') as fromdate, to_date('10.04.2013','dd.mm.yyyy') as todate
)

这个显示如下:

Process     Fromdate       Todate
-----------------------------------------
   A       03.04.2013     06.04.2013
   B       06.04.2013     10.04.2013

但我需要这样的查询结果:

 Process       Date
-----------------------
   A        03.04.2013
   A        04.04.2013
   A        05.04.2013
   B        06.04.2013
   B        07.04.2013
   B        09.04.2013

我该怎么做?

... thaks

1 个答案:

答案 0 :(得分:0)

select process, from_date + n
from (
    select process, fromdate, todate from
    (
       select 'A' as process, to_date('03.04.2013','dd.mm.yyyy') as fromdate, to_date('06.04.2013','dd.mm.yyyy') as todate
       UNION
       select 'B' as process, to_date('06.04.2013','dd.mm.yyyy') as fromdate, to_date('10.04.2013','dd.mm.yyyy') as todate
    ) s
join 
    (select level -1 as n from dual connect by level < 100) a
on (s.from_date+n < s.todate)