Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Tree structure

Re: Tree structure

From: Sean Kelly <sean.k_at_mindspring.com>
Date: 1998/02/23
Message-ID: <6cs6ba$nb2@camel19.mindspring.com>#1/1

    ªü¼Ö¥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
          ...  ... ... ...

    query for group b will included e, f ... etc.     thanks in advice.

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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US