当前位置: 移动技术网 > IT编程>数据库>Oracle > oracle SQL递归的使用详解

oracle SQL递归的使用详解

2017年12月12日  | 移动技术网IT编程  | 我要评论

fc2视频破解,vcfeditor,总理翻译孙宁

oracle数据库中如果需要使用sql递归语句,应该怎么写呢?下面就为您介绍一个oracle中使用sql递归语句的例子,供您参考。
例子:
复制代码 代码如下:

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语句:select   parent,child   from   test   start   with   pid='a'  
connect   by   prior   id=pid

oracle  sql递归查询语句:
1、表机构
复制代码 代码如下:

sql> desc comm_org_subjection
 name                                      null?    type
 ----------------------------------------- -------- ----------------------
 org_subjection_id                         not null varchar2(32)   子键
 org_id                                    not null varchar2(32)
 father_org_id                             not null varchar2(32)   父键
 locked_if                                 not null varchar2(1)
 start_date                                not null date
 end_date                                           date
 edition_nameplate                                  number(8)
 code_afford_if                                     varchar2(1)
 code_afford_org_id                        not null varchar2(32)
 coding_show_id                                     number(8)
 bsflag                                             varchar2(1)
 modifi_date                                        date
 creator_id                                         varchar2(32)
 create_date                                        date
 creator                                            varchar2(35)

2、递归查找父结点 org_id为c6000000000001下的所有子结点:
复制代码 代码如下:

select * from comm_org_subjection a
start with a.org_id='c6000000000001'
connect by prior a.org_subjection_id=a.father_org_id

3、递归查找子结点 org_id为c6000000000001下的所有父结点:
复制代码 代码如下:

select org_id from comm_org_subjection a
start with a.org_id='c6000000000001'
connect by prior a.father_org_id=a.org_subjection_id

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网