隨筆-13  評論-28  文章-63  trackbacks-0
          DEPTID PAREDEPTID NAME
          NUMBER NUMBER CHAR (40 Byte)
          部門id 父部門id(所屬部門id) 部門名稱

          通過子節點向根節點追朔.

          select * from persons.dept start with deptid=76 connect by prior paredeptid=deptid

          通過根節點遍歷子節點.


          select * from persons.dept start with paredeptid=0 connect by prior deptid=paredeptid 

          可通過level 關鍵字查詢所在層次.


          select a.*,level from persons.dept a start with paredeptid=0 connect by prior deptid=paredeptid

          再次復習一下:start with ...connect by 的用法, start with 后面所跟的就是就是遞歸的種子。

          遞歸的種子也就是遞歸開始的地方 connect by 后面的"prior" 如果缺省:則只能查詢到符合條件的起始行,并不進行遞歸查詢;

          connect by prior 后面所放的字段是有關系的,它指明了查詢的方向。

          練習: 通過子節點獲得頂節點

          select FIRST_VALUE(deptid) OVER (ORDER BY LEVEL DESC ROWS UNBOUNDED PRECEDING) AS firstdeptid from persons.dept start with deptid=76 connect by prior paredeptid=deptid 
          posted on 2008-11-13 14:27 七匹狼 閱讀(373) 評論(0)  編輯  收藏 所屬分類: oracle
          主站蜘蛛池模板: 怀仁县| 博爱县| 环江| 肥乡县| 桐乡市| 红河县| 双辽市| 方城县| 义乌市| 吉首市| 龙井市| 太康县| 陆良县| 武清区| 平陆县| 中牟县| 潼南县| 横山县| 千阳县| 珠海市| 武功县| 五华县| 江永县| 辽源市| 子洲县| 上高县| 微博| 遂溪县| 庐江县| 黎城县| 福贡县| 绍兴市| 陆丰市| 潞城市| 乐陵市| 砚山县| 陇南市| 大兴区| 张北县| 彭泽县| 遂溪县|