Home > Software engineering >  How can I display result in order of hierarchy (in Oracle SQL Developer)?
How can I display result in order of hierarchy (in Oracle SQL Developer)?

Time:06-28

I have a dataset where first column is employee code and second column is manager code. I am trying to output an extract where reporting structure is clearly visible. How can I do that? I would appreciate any clues. Below are sample dataset and expected output.

Dataset

Expected Output

CodePudding user response:

You simply need a CONNECT BY clause and LPAD function combination -

 SELECT LPAD('*', LEVEL - 1, '*') || col_org Col_hierarchy_org
   FROM DATA D
  START WITH col_org_predecessor IS NULL
CONNECT BY PRIOR col_org = col_org_predecessor;

Demo.

  • Related