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.7 Leveled Adjacency List Model > 2.7.2 Aggregation in the Hierarchy - Pg. 46

2.7 Leveled Adjacency List Model 31 2.7.1 Numbering Levels Assigning level numbers is a simple loop, done one level at a time. Let's assume that all level numbers start as zeros. CREATE PROCEDURE RenumberLevels() LANGUAGE SQL DETERMINISTIC BEGIN ATOMIC DECLARE lvl_counter INTEGER; SET lvl_counter = 1; -- set root to 1, others to zero UPDATE Tree SET lvl = CASE WHEN boss_emp_name IS NULL THEN 1 ELSE 0 END; -- loop thru lvls of the tree WHILE EXISTS (SELECT * FROM Tree WHERE lvl = 0)