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

Home -> Community -> Usenet -> c.d.o.misc -> Re: SELECT CONNECT BY...

Re: SELECT CONNECT BY...

From: michael ringbo <mri_at_dde.dk>
Date: 1998/02/25
Message-ID: <34F3DB88.DAEBD839@dde.dk>#1/1

Hi,

Try building a table:
create table my_tab (parent number(1), son number(1));

Insert following values:

insert into my_tab values(1,2);
insert into my_tab values(1,3);
insert into my_tab values(2,4);
insert into my_tab values(2,5);
insert into my_tab values(3,6);
insert into my_tab values(5,7);
insert into my_tab values(5,8);

Try doing the select:
select parent,son,level
from my_tab
connect by prior son=parent
start with parent = 1
order by level;

You get the result:

    PARENT SON LEVEL
---------- ---------- ----------

         1          2          1
         1          3          1
         2          4          2
         2          5          2
         3          6          2
         5          7          3
         5          8          3

Hope you see the fathers, sons and grandpa's!

Notice: If you leave out the order by you get a depth-first traverse of the tree. Try it out.

Regards,

Michael Ringbo, mri_at_dde.dk

dicaprio wrote:

> Hi,
>
> Someone can help me with an example about :
>
> "You use LEVEL with the SELECT CONNECT BY statement to organize rows
> from
> a database table into a tree structure. LEVEL returns the level number
> of a
> node in a tree structure. The root is level 1, children of the root
> are
> level 2, grandchildren are level 3, and so on..."
>
> Thanks in advances
> Veramente Grato....
>
> Clemente di Caprio
>
> dicaprio_at_tin.it
Received on Wed Feb 25 1998 - 00:00:00 CST

Original text of this message

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