Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: smashed by a problem: query to groupped hierarchical data
"T-BAG" <T-BAG_at_prisonbreak.invalid.com> a écrit dans le message de news: 0001d251$0$2920$c3e8da3_at_news.astraweb.com...
|> SQL> with| > 13 ),
| > 2 data as (
| > 3 select connect_by_root child root, grp,
| > 4 decode(grp,
| > 5 null,ar||'('||child||')',
| > 6 substr(sys_connect_by_path(ar||'('||child||')',','),
| > 7 instr(sys_connect_by_path(ar||'('||child||')',','),
| > 8 ',',2)+1))
| > 9 elem
| > 10 from t
| > 11 connect by prior child = parent and nvl(prior grp,grp) = grp
| > 12 start with parent is null
| | Hello, | | Michel, thanks for the code. It is impressive to me. I tried to find out | what the stragg function is, and found Tom Kyte's solutions of the same | name. I used the code found here: | | http://www.dbazine.com/oracle/or-articles/tropashko2 | | but I get different result than yours, ie. the "without group" colum is | 'a(p1)a(p2)a(p3)' but others are null. | | Could you post your definition of stragg function? | | Thank you, | T-BAG
I don't think I use the latest version.
I use the first one you'll find at
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402
You can do it without stragg function but it is harder to read and slower.
It is not such impressive.
The first part is just a standard hierarchical query, only the way you want
to display the data turn it to something harder to read ("A/R(child)" form).
The second part just groups the data within the groups you defined
(group null, other groups T with parent P1 and with parent non P1...)
with the help of a decode (a case should be easier to read).
The last part is a standard rows to columns pivot to display on one line.
As it, it works for 2 levels and I think you have to enhance it to get the output you want if you have more than 2 levels (in this case what you should be the result?).
Regards
Michel
Received on Sat Jul 28 2007 - 01:58:45 CDT