Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> tree structures in database tables?
Hi all -
I'm looking for a SQL statement or PL/SQL procedure to output the ordered
structure of a data tree held in my Oracle database table. Unfortunately
it didn't end up as easy as I first thought and I'm looking for a hand.
Here's what I've got:
I've a table that sets up a kind of tree, with the following columns:
table REGIONS
region_id CHAR(4) region_name VARCHAR2(20) region_group CHAR(4)
The regions are hierarchical; for example I might have City of Seattle within King County within Puget Sound Area within State of WA, etc. So some table entries might look like this:
REGION_ID REGION_NAME REGION_GROUP --------- ---------------- ------------ SEAT City of Seattle KING BELL City of Bellevue KING KING King County PUGS PUGS Puget Sound Area WAST WAST State of Washington null ORST State of Oregon null SOMC Some County in OR ORST
What I first tried to list this out was something along the lines of: SELECT a.region_name, b.region_name, c.region_name FROM regions a, regions b, regions c
WHERE a.region_group = NULL AND b.region_group = a.region_id AND c.region_group = b.region_id
But the problem is, as I mentioned above, my tree-depth doesn't stay constant, while this statement requires a specific depth. Also, my tree-depth is also generally much deeper than the above example, making for a really icky SQL statement anyways. And that's where I'm stuck.
A guy in another newsgroup said he remembered some kind of Oracle extensions to handle tree-structured data in tables, but he didn't remember what they were and I can't seem to find anything about it in my manuals. Any of y'all familiar with that? Or have a good way through my problem?
Much thanks in advance!
Cheers,
-Andy Ganse
Received on Mon Feb 23 1998 - 00:00:00 CST