Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Parent-Child query technique?

Re: Parent-Child query technique?

From: Gerard H. Pille <ghp_at_skynet.be>
Date: Thu, 18 Oct 2007 20:43:16 +0200
Message-ID: <4717a944$0$29263$ba620e4c@news.skynet.be>


SpaceMarine wrote:
> hello,
>
> i am interested in building a query on oracle 9.2 (i think). i guess
> youd call it a "parent-child" report query... i have a view that lists
> a bunch of parts, and each of these parts can be either a parent or
> child to another part in the same view. each part/row has columns for
> PartID, Name, ParentID.
>
> i would like to present one result that lists all of the parts, but
> groups each part's child parts under it before moving to the next
> part. this children-list grouping should nest indefinitely for the
> children's children, etc, until the end-of-the-line is met for one
> ancestry. then the next brand new entity is listed. like so:
>
> Part_1
> Child_1
> Grandchild_1
> Grandchild_2
> GreatGrandchild_1
> Child_2
> Child_3
> Part_2
>
> im afraid this is a bit outside of my normal CRUD experience. can
> anyone offer me suggestion or syntax on how such a report is written?
> (im sure im not the first joe who needs a report like this). much good
> fortunte & luck will be bestowed upon you....
>
>
> thanks!
> sm
>

select rpad(' ',level*4) || name

   from parts
   start with parentid is null
   connect by parentid = prior partid

it's called a treewalk or hierarchical query Received on Thu Oct 18 2007 - 13:43:16 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US