阅读557 返回首页    go 技术社区[云栖]


oracle中使用SQL递归语句

场景:常见的领导关系树结构,知道某一节点ID,要查出此节点的所有下级(直接下级和间接下级),此时需要使用SQL递归语句。

oracle中的递归语句: 
None.gifstart   with   dot.gifdot.gif  connect   by   prior  dot.gif.


例子:

 pid  id
  a   b  
  a   c    
  a   e  
  b   b1  
  b   b2  
  c   c1  
  e   e1  
  e   e3  
  d   d1  
   
  指定pid=a,选出  
  a   b  
  a   c    
  a   e  
  b   b1  
  b   b2  
  c   c1  
  e   e1  
  e   e3 
SQL语句:
None.gif  select   parent,child   from   test   start   with   pid='a'   
None.gif  connect   
by   prior   id=pid 
文章转自庄周梦蝶  ,原文发布时间5.17

最后更新:2017-05-17 11:32:53

  上一篇:go  Plug memory leaks in enterprise Java applications
  下一篇:go  《时代》评选17年100位全球影响力人物,滴滴柳青、DeepMind创始人等科技大佬上榜