Hi Every one
I'm trying to learn oracle hierarchy query and spent couples of hours but still not getting it. Suppose I have the following query:
Query
WITH
DATA AS
(
select '100' grp, '01-JAN-2012' effective_date, '30-JUN-2012' termination_date from dual
union all
select '100' grp, '01-JUL-2012' effective_date, '05-AUG-2012' from dual
union all
select '100' grp, '06-AUG-2012' effective_date, '10-AUG-2012' from dual
union all
select '100' grp, '02-AUG-2012' effective_date, '09-AUG-2012' from dual
),
correct_data as (
select grp,
to_date(effective_date, 'DD-MON-YYYY','NLS_DATE_LANGUAGE=ENGLISH') effective_date,
to_date(termination_date, 'DD-MON-YYYY','NLS_DATE_LANGUAGE=ENGLISH') termination_date
from data
)
select grp, effective_date, termination_date,level
from correct_data
connect by prior termination_date = effective_date-1
and prior grp = grp
start with (effective_date)
in (select min(effective_date) from correct_data )
order by 1, 2;
Query result
100 01-JAN-12 30-JUN-12 1
100 01-JUL-12 05-AUG-12 2
100 06-AUG-12 10-AUG-12 3
I don't understand why I'm getting this result and not getting the remaining 1 row. if someone explain this in details in simple words then I really appreciate it. Thanks in advance.
Regards
Shumail