数据库
首页 > 数据库> > 1、Oracle单位查询

1、Oracle单位查询

作者:互联网

select dwdm,dwmc,pdwdm, dwpx,isleaf,jb,nvl(dwdmpath, dwdm) rootpdwdm
     from (select dwdm,dwmc,pdwdm,dwpx,dwjc isleaf,jb,
                  --正则表达式截取字符串,以斜杠为匹配分割符
                  REGEXP_SUBSTR(path, '[^/]+', 1,jb) dwdmpath
              from (select t.*,
                           --树的最末端,树枝下已经没有树叶了
                           connect_by_isleaf || '' isleaf,
                           --数据属于 哪一个等级
                           level || '' jb,
                           --显示详细路径,并用“/”分隔
                           sys_connect_by_path(dwdm, '/') path
                           --CONNECT_BY_ROOT 返回当前节点的最顶端节点
                       from sjc_dw t  connect by prior dwdm = pdwdm   start with pdwdm is null                     
                    )
          )

标签:pdwdm,--,查询,单位,isleaf,dwdm,Oracle,jb,connect
来源: https://blog.51cto.com/14792714/2692581