Here's the full example data set for this query without any pruning of trees where no node matches the search string:
Level parent id text --------------------------------------------- 0 0 1 toplevel 1 1 2 foo 1 1 3 sumthin else 1 1 4 foo 0 0 7 toplevel2 1 7 8 secondlevel 1 7 9 anothersecondlevel
I need to return the following if the user searches on 'foo':
0 0 1 toplevel 1 1 2 foo 1 1 4 foo
The real case is a bit more complex (i.e., three levels in the tree that I want to return) but this captures the issue. In English, return the ancestor tree for an node that matches the search string starting at the matching node on text column and return all ancestors.
I am new to Oracle (at least recently) and have tried adding to the CONNECT BY clause without any success - always returns the following:
1 1 2 foo 1 1 4 foo
PS - the oracle docs and examples on this imply that CONNECT_BY_ROOT will capture the ancestors but all it seems to do is return top level (ROOT) values.
Depending upon your use of the LEVEL column (as per my comment).
Info on Oracle Hierarchical Queries: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm
This returns what you ask for if LEVEL is the Oracle pseudocolumn:
Returns:
If LEVEL is a column in your table then:
Returns:
Hope it helps...