create table wzh_test_date(begin_date date,end_date date)
truncate table wzh_test_date
insert into wzh_test_date values(trunc(sysdate,'dd'),trunc(sysdate,'dd')+1);
insert into wzh_test_date values(trunc(sysdate,'dd')+1,trunc(sysdate,'dd')+2-1/24);
insert into wzh_test_date values(trunc(sysdate,'dd')+2,trunc(sysdate,'dd')+3-1/12);
insert into wzh_test_date values(trunc(sysdate,'dd')+3,trunc(sysdate,'dd')+4);
insert into wzh_test_date values(trunc(sysdate,'dd')+4,trunc(sysdate,'dd')+5+1/24);
insert into wzh_test_date values(trunc(sysdate,'dd')+5,trunc(sysdate,'dd')+6+2/24);
insert into wzh_test_date values(trunc(sysdate,'dd')+6,trunc(sysdate,'dd')+7);
with rs
as (select begin_date,end_date,row_number()over(order by begin_date)row_no,row_number()over(order by begin_date)-1 row_no_desc
from wzh_test_date)
select mt1.begin_date,mt2.end_date
from
(select l.begin_date,l.end_date,row_number()over(order by l.begin_date)row_no
from rs l
left join
rs r
on l.row_no-1=r.row_no
and l.begin_date=r.end_date)mt1
join
( select r.begin_date,r.end_date,row_number()over(order by r.begin_date)row_no
from rs l
right join
rs r
on l.row_no-1=r.row_no
and l.begin_date=r.end_date)mt2
on mt1.row_no=mt2.row_no
order by mt1.begin_date
with rs
as (select begin_date,end_date,row_number()over(order by begin_date)row_no,row_number()over(order by begin_date)+1 row_no_desc
from wzh_test_date)
select connect_by_root begin_date,rs.*,level,CONNECT_BY_ISLEAF isleaf
from rs
connect by nocycle (prior end_date=begin_date)