Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Tree structure
ªü¼Ö¥K wrote in message <34F0F581.356BE29F_at_geocities.com>...
Hi,
Does anyone know how to implement a tree data structure into RDBMS ? and
provide a grouping
query for any note within the tree.
e.g.
a / \ b c / \ / \ e f g h ... ... ... ...
Depends on how you want to do the scanning and whether you want to limit the number of children. It ends up being a self-referential table either way. If you want to scan from the top down or limit the number of children to 2 (as the binary tree you have does) then I'd do something like this:
mykey int index, mydata char(32), left int, right int
Where left and right are the values of the 'mykey' values of the left and right children. If you want to have an unlimited number of children you may want to do it this way:
mykey int index, mydata char(32), parent int
In any case, you get the idea :)
-sean Received on Mon Feb 23 1998 - 00:00:00 CST