I have been trying to work out the solution to this problem and have found a solution.
Please correct me if you think there is any issue with this below SQL:
select *
from (SELECT root as per_id2,
per_id1,
PER_LEVEL,
(case
when max(connect_by_root start_dt) >= max(start_dt) then
max(connect_by_root start_dt)
else
max(start_dt)
end) as max_start,
(case
when min(connect_by_root end_dt) <= min(end_dt) then
min(connect_by_root end_dt)
else
min(end_dt)
end) AS min_end
FROM (SELECT connect_by_root per_id2 AS root,
per_id1,
per_id2,
level as per_level,
(case
when connect_by_root start_dt >= start_dt then
connect_by_root start_dt
else
start_dt
end) as start_dt,
(case
when connect_by_root end_dt <= end_dt then
connect_by_root end_dt
else
end_dt
end) as end_dt
FROM ci_per_per
CONNECT BY NOCYCLE PRIOR per_id1 = per_id2)
CONNECT BY NOCYCLE PRIOR per_id1 = per_id2
and PRIOR root = root
GROUP BY per_id1, per_id2, root, per_level)
where max_start <= min_end
Here's the fiddle for the same