Tree Walking

TREE WALKING
      A Relational database does not stpre records in a hierarchical way however where a hierarchical relationship exists between the rows of a single table there is a process called tree walking which enables the hierarchy to be constructed . the hierarchy cab be created by looking at the relationship between equivalent values in columns empno and mgr am employee’s mgr number us their managers empno.
Ex:-select level,deptno,empno,ename,job,sal
       from emp
       connect by prior empno=mgr
       start with mgr is NULL;
Options
Select :                  Standard Sql Select
From :                   You can select from only one table
Where:                  Restricts rows that are visited during the walk
Connect by:          specifies the columns where the relationship between rows                                       exists. This caluse is required for tree walk
Prior         :           Establishes the direction in which the tree is walked . if prior                                   appears before mgr then value in mgr column one visited first                             then equivalent empno value are found, that is up the tree. If                                 prior appears before empno then tree walk is down
Start with :           specifies where to start the walk cannot start at a level this                                       clause is optional even when requesting a tree walk.
ORDER BY:        appears at the end as usual.

 

 

For
Online Classes

Contact Us: +919885348743