Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

2.4 Navigation in Adjacency List Model > 2.4.4 Finding a Subtree with Iteration... - Pg. 39

24 CHAPTER 2: ADJACENCY LIST MODEL SELECT P1.emp_name, P1.boss_emp_name, (T.recurse_depth +1) AS recurse_ depth FROM Personnel_OrgChart AS P1, Traversal AS T WHERE T.emp_name = P1.boss_emp_name ) SELECT emp_name, boss_emp_name, recurse_depth FROM Traversal; This is actually implemented as a loop and cursors inside most SQL products. However, this declarative from has some chance of being optimized in the future, whereas loops and cursors do not. 2.4.4 Finding a Subtree with Iterations This procedure will find the subtree rooted at the manager emp_nbr of your PersonnelOrg table. The idea is simple. Create a local working table and load it with the immediate subordinate emp_nbrs. Using the leaf nodes in a loop, find their subordinates. When you can add no more levels to the working