0

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

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

我怎样才能做到这一点?

谢谢...

4

1 回答 1

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)
于 2013-07-03T07:26:06.973 回答