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!

traversing a tree

user13168644Jan 8 2019 — edited Jan 8 2019

Hi,

 I have a employee table, with two additional columns that stores the node number (left and right) for a tree for hierarchy  . There is a procedure that computes the node number and stores when a new employee is added. The idea is to list all the employees who work under a manager , all the way to the bottom.  So the structure is something like this

| ID | Name | lft | rgt |
| 1 | John | 315300 | 595600 |
| 2 | Adam | 519000 | 522700 |
| 3 | Lisa | 520500 | 521400 |
| 4 | Sally | 389400 | 389500 |
| 5 | Robert | 670200 | 1098300 |
| 6 | Jerry | 910100 | 950000 |
| 7 | Fred | 937600 | 939300 |
| 8 | Alex | 289200 | 1432300 |

Here is the tree

tree.jpg

I need a query to traverse the tree from any point ( any manager at any level ). So I should be able to see all the employees working for John, or all the employees working for Robert or both together .

Thanks

This post has been answered by Frank Kulash on Jan 8 2019
Jump to Answer
Comments
Post Details
Added on Jan 8 2019
15 comments
539 views