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: query to trace all parents

Re: query to trace all parents

From: Ed Prochak <ed.prochak_at_magicinterface.com>
Date: 23 Jun 2005 11:33:27 -0700
Message-ID: <1119551607.881092.169190@g43g2000cwa.googlegroups.com>


CONNECT BY is your friend. It can be tricky but here's an example based on your data:

SQL> create table ejp (
  2 p char(1), c char(1) );

Table created.

SQL> insert into ejp values ( 'a', 'b');

1 row created.

SQL> insert into ejp values ( 'b', 'c');

1 row created.

...
SQL> select * from ejp;

P C
- -

a b
b c
b e
c d
e f
e g

6 rows selected.

SQL> select p from ejp start with c='f'
  2 connect by c=prior p;

P
-

e
b
a

SQL> HTH,
  Ed Received on Thu Jun 23 2005 - 13:33:27 CDT

Original text of this message

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