查询以查找文件夹路径和叶节点ID

时间:2019-03-07 16:06:03

标签: sql oracle hierarchical-data recursive-query

我的桌子为

enter image description here

我想创建SQl或过程来获取以下值

 FolderPath          LeafFolderID 

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

请让我知道如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

connect by完成了任务:

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