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

Query to find folder path and leaf node ID

我有 table 作为

我想创建 SQl 或程序来获取如下值

 FolderPath          LeafFolderID 

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

请告诉我如何实现这个?

这个 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