Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unable to get the idea of hierarchy query

MuzzJun 14 2013 — edited Jun 17 2013

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

This post has been answered by Frank Kulash on Jun 14 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2013
Added on Jun 14 2013
9 comments
1,832 views