用SYS_CONNECT_BY_PATH进行层级查询时的排序问题

Posted 轻云悠然舞月光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用SYS_CONNECT_BY_PATH进行层级查询时的排序问题相关的知识,希望对你有一定的参考价值。

 

 

用SYS_CONNECT_BY_PATH进行层级查询时, 对同一级别的节点进行排序,可以加order SIBLINGS by 子句实现

WITH N2 AS(
    SELECT n.ID, org."ParentID", n."NodeName", n."Sort" FROM "Organize" org
    LEFT JOIN "Node" n ON n."ID"=org."NodeID"
    WHERE n."DeleteTime" IS NULL AND n."RefreshTime" is NULL
    ORDER BY "ParentID", "Sort" ASC
)
    SELECT "ID",   "ParentID", "NodeName", 
    SYS_CONNECT_BY_PATH("ID",\)   ID_PATH, SYS_CONNECT_BY_PATH("NodeName",\)  NAME_PATH, LEVEL, "Sort"
    FROM N2

    START   WITH "ParentID"=# OR "ParentID" IS NULL
    CONNECT BY PRIOR "ID"="ParentID"
    order SIBLINGS by "Sort" ASC

 

参考文献:https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1154964870586

以上是关于用SYS_CONNECT_BY_PATH进行层级查询时的排序问题的主要内容,如果未能解决你的问题,请参考以下文章

浅谈oracle树状结构层级查询测试数据

能力层书写规范

Oracle函数sys_connect_by_path 详解

Oracle中SYS_CONNECT_BY_PATH函数的妙用 ;

vue层级关系的数据管理

Oracle怎么嵌套查询