RE: Building a tree recursively
Posted in 1998
Simon; (And all who responded) Thanks for your help. I decided to sit down and find another less finesse, more brute force way to do this Friday. It turned out almost identical to your method. I'm getting some duplicates, but I'll iron out the bugs this morning. Thanks again. } -----Original Message----- } From: Simon Burrows [SMTP:simon@calyps0.demon.co.uk] } Sent: None } To: sblack@elsouth.com } Subject: Re: Building a tree recursively } } } Duplicate of article posted to comp.databases.informix } } } } Anyway here's an approach I might at least examine if I had a similar } problem. It is flat (non-recursive - which upsets me as I like } recursion) } and doesn't explicitly use any cursors but it does let the Engine take } the } strain. } } FUNCTION get_children(unit_no) } } DECLARE } cur_count INTEGER, } last_count INTEGER } } create temp table descend(child_no integer) } } INSERT INTO descend } SELECT child_no } FROM unit_link } WHERE parent_no = unit_no } } SELECT count(*) } INTO cur_count } FROM descend } } LET last_count=cur_count - 1 } } WHILE cur_count > last_count } INSERT INTO descend } SELECT unit_link.child_no } FROM unit_link,descend } WHERE unit_link.parent_no=descend.child_no } AND unit_link.child_no IS NOT IN ( SELECT child_no } FROM descend ) } } LET last_count=cur_count } } SELECT count(*) } INTO cur_count } FROM descend } } END WHILE } } # Use descend table } } DROP TABLE descend } } END FUNCTION } } Hope this helps } Simon } } } David Williams <djw@smooth1.demon.co.uk> wrote: } } > Create a "cursor mangement" library:- } } >> Is there another way to go about this w/o recursion? What methods } have } >> any of you used to solve similar problems? } >> } >> TIA } >> BTW this is HP-UX 10.20 OnLine 7.22 4GL 6.04