I'm trying to figure out how to query DTREEANCESTORS to return row information like "Item (folder or document) X is an Nth level child of Folder Y". A returned row would look something like {DataID, Depth, AncestorID}. I was thinking of a CONNECT BY PRIOR type of query but the data in DTREEANCESTORS is problematic. DTREEANCESTORS stores a row for every Ancestor, regardless of the generational separation. If an item is nested two or more levels deep, then there are multiple paths that can be followed. You also need to exclude all of the rows that identify an item as an ancestor of itself.
Here is an example to illustrate the problem, with data from one of our DEV databases:
DATAID ANCESTORID
2111 2001
2991 2001
2991 2111
2991 2991
2001 and 2111 represent folders, where 2111 is a sub-folder of 2001. 2991 is a document contained in 2111. As you can see, 2991 is identified directly as a child of 2001, and also as a grandchild via 2111. What I want to see returned by the query for DataID=2991 is the following:
DATAID ANCESTORID DEPTH
2991 2001 2
2991 2111 1
Given the redundant paths in the data between 2991 and 2001, I don't see how to achieve this using CONNECT BY PRIOR. Does anyone see any flaw in my reasoning, or have a solution to my problem?
Thanks
Patrick