Following an example of source table:
CREATE TABLE TEST_HIER
(
ID NUMBER,
PID NUMBER
);
Insert into TEST_HIER
(ID, PID)
Values
(1, 0);
Insert into TEST_HIER
(ID, PID)
Values
(2, 1);
Insert into TEST_HIER
(ID, PID)
Values
(3, 1);
Insert into TEST_HIER
(ID, PID)
Values
(4, 2);
Insert into TEST_HIER
(ID, PID)
Values
(5, 3);
COMMIT;
And expected result is:
PID CHILD
---------- ----------
0 1
1 2
2 1
3 1
Any idea?
Thanks a lot
Mauro
explore connect by clause.
.......
We run Oracle 9iR2,10gR2, 10g2RAC on RH4/RH5 and Solaris 10 (Sparc)
remove NSPAM to email
NetComrade,
are you referring to http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns001.htm#i1007332
?
Regards
Mauro
This is probably a better place to start:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries003.htm#i2053935
I never actually wrote one, but that's the way to go :)
Also search asktom.oracle.com for "connect by" for examples
Netcomrade,
my post is just a "joke" to find different solution to achieve it.
The straight way to do what I asked is to use connect_by_isleaf (it's
why I've pointed out that doc page).
My question is "in your opinion, which could be another way to achieve
it?"
Regards
Mauro
As you are counting only direct children, the number of children is
exactly the same, as every parent is referenced. So, you don't need
connect by at all, simple
select pid,count(*)
from test_hier t
group by pid
gives you expected output.
Best regards
Maxim
He didn't state it, however it is the only conclusion i can make,
comparing his input data and expected output.
Best regards
Maxim