which gives:
PCODE LEVEL DESCRIPTION A FIN_PCODE
---------- ---------- --------------------------
1 1 p1 Y
3 2 p3 Y 1
6 3 p6 Y 3
Main Topics
Browse All Topics





by: ishandoPosted on 2004-04-20 at 17:06:31ID: 10873677
with table:
----
---- - ----------
create table pcodes (pcode int, active char(1), fin_pcode int, descrip varchar2(30));
and data
PCODE A FIN_PCODE DESCRIP
---------- - ---------- --------------------------
1 Y p1
2 N 1 p2
3 Y 1 p3
4 Y 2 p4
5 Y 2 p5
6 Y 3 p6
your current query gives:
PCODE LEVEL DESCRIPTION A FIN_PCODE
---------- ---------- --------------------------
1 1 p1 Y
4 3 p4 Y 2
5 3 p5 Y 2
3 2 p3 Y 1
6 3 p6 Y 3
If what you want is to omit the branch from pcode 2, try this:
select pcode, level, LPAD(' ',2*(LEVEL-1)) || descrip description, active, FIN_PCODE
from PCODES
start with FIN_PCODE is null
connect by prior PCODE = FIN_PCODE
and prior active = 'Y' and active = 'Y'
ORDER SIBLINGS BY descrip;