James 发表于 2016-11-15 07:37:59

db2 递归函数小示例

with rpl(id,name,parent) as (
select id,name,parent from A_ORGAN where id=999
union all
select t1.id,t1.name,t1.parentfrom rpl t2,A_ORGAN t1 where t2.id=t1.parent
)
selectdistinct id,name,parent from rpl order by id asc
 
select t1.id,t1.name from A_ORGANt1 where  t1.ID=999 or t1.PARENT=999 order by t1.id asc
页: [1]
查看完整版本: db2 递归函数小示例