Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to put hierarchy into columns
jaspas_at_poczta.onet.pl wrote:
> Hello,
>
> I have table:
>
> create table corporate_slaves (
> slave_id integer primary key,
> supervisor_id references corporate_slaves,
> name varchar(100)
> );
>
> insert into corporate_slaves values (1, NULL, 'Big Boss');
> insert into corporate_slaves values (2, 1, 'VP Mark');
> insert into corporate_slaves values (3, 1, 'VP Sal');
> insert into corporate_slaves values (4, 3, 'Joe');
> insert into corporate_slaves values (5, 4, 'Bill');
> insert into corporate_slaves values (6, 1, 'VP Engi');
> insert into corporate_slaves values (7, 6, 'Jane');
> insert into corporate_slaves values (8, 6, 'Bob');
>
>
> How I can put hierarchy into columns to get result like this:
>
> Parent Parent-1 Parent-2 Parent-3 Parent -4
> Lowest
> -------------- ------------ -------------- ------------
> -------------- ------------
> Big Boss
> Big Boss
> Big Boss VP Mark
> VP Mark
> Big Boss Vp Sal
> VP Sal
> Big Boss VP Sal Joe
> Joe
> Big Boss VP Sal Joe Bill
> Bil
> Big Boss VP Engi
> Engi
> Big Boss VP Engi Jane
> Jane
>
>
> I used simply "connect by" but it's not what I need
>
> SELECT LPAD(' ',(LEVEL-1)*4,' ')||name
> FROM corporate_slaves
> CONNECT BY PRIOR slave_id=supervisor_id
A problem with hierarcky doesn't necessarily imply the need in hierarchical query
select ... from
corporate_slaves cs_level1, corporate_slaves cs_level2, corporate_slaves cs_level3, corporate_slaves cs_level4,
P.S. Appreciate your sence of humor Received on Wed Nov 23 2005 - 16:15:38 CST