| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Storing hierarchical information?
In article <slrn9fdnor.iqd.criscokid_at_deepcore.gsm>, Dave Kimmel says...
>
>So, what I want to ask is this: Is there any "proper" way to store
>hierarchical data in a database, much like operating systems store
>files? Is what I'm doing fine, or is there a way that could be
>faster?
Dave,
Question how to store tree in the database surface now and then, and many would pointer to J.Celko's method. IMHO, more superior method is to materialize a path in some way. Below is extract from some old thread.
If you just store path as a string
('1.0')
/ | \
/ | \
/ | \
/ | \
('1.1') ('1.2') ('1.3')
/ \ / \ |
/ | / \ |
then you would be able to query like this:
select node from tree where SUBSTR('1.2.2.3', 1, LENGTH(node))=node
returns all the nodes above 1.2.2.3.
select node from tree where SUBSTR(node, 1, LENGTH('1.2.2'))='1.2.2'
returns everything below 1.2.2.
select node from tree where SUBSTR('1.2.2.3', 1, LENGTH(node))=node and NODELEVEL('1.2.2.3')=NODELEVEL(NODE)+1
returns node's parent. Received on Mon May 07 2001 - 13:46:37 CDT
![]() |
![]() |