Reputation: 21897
I'm having a table with the following data
Col1 Col2
---------------
P null
C1 P
C2 P
C11 C1
C12 C1
C21 C2
Col2 indicates the parent column.
I want to display the data in the tree form
P
|_C1
| |_C11
| |_C12
|_C2
|_C21
Is there any tool/program that displays database records in the tree format?
Upvotes: 0
Views: 253
Reputation: 1135
If you are using Oracle:
Try hierarchical queries. Use LEVEL
and CONNECT_BY_ISLEAF
pseudo columns to decide if leading lines need to be drawn and how.
Something like this:
SELECT CASE WHEN LEVEL = 1
THEN col1
ELSE LPAD( '_' || col1, ( LEVEL - 1 ) * 4, '| ' )
END output
FROM tab1
CONNECT BY PRIOR col1 = col2
START WITH col2 IS NULL;
Upvotes: 1