Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: query to trace all parents
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