0

I have table as

enter image description here

I want to create SQl or Procedure to fetch values as below

 FolderPath          LeafFolderID 

 Dept/CSE/Cfolder     100
 Dept/Mech            10
 Team/HR              22
 Settlement           3

Please let me know how to achieve this?

nkm
  • 53
  • 1
  • 8

1 Answers1

1

This connect by does the job:

select folderid, ltrim(sys_connect_by_path(foldername, '/'), '/') path
  from t
  where connect_by_isleaf = 1
  connect by folderparentid = to_char(prior folderid)
  start with folderparentid = 'Root'

demo

Ponder Stibbons
  • 14,723
  • 2
  • 21
  • 24