码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 树操作

时间:2016-09-26 19:40:53      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 select…start with…connect by…prior

1.查找一个节点的所有直属子节点(节点本身+所有后代),有以下两种写法。

select id, typename, typecode, parentid, ordernum
from purchase_type
where status = 1
  start with id = 15
  connect by parentid = prior id
  order siblings by ordernum

select id, typename, typecode, parentid, ordernum
from purchase_type
where status = 1
  start with id = 15
  connect by prior id = parentid
  order siblings by ordernum

显示结果:

技术分享

2.查找一个节点的所有直属父节点(节点本身+所有祖宗(父类的父类....))。

select id, typename, typecode, parentid, ordernum
from purchase_type
where status = 1
  start with id = ‘136‘
  connect by id = prior parentid
  order siblings by ordernum

select id, typename, typecode, parentid, ordernum
from purchase_type
where status = 1
    start with id = 136
    connect by prior parentid = id
    order siblings by ordernum

显示结果:

技术分享

Oracle 树操作

标签:

原文地址:http://www.cnblogs.com/chengx/p/5910227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!