---
title: "工作日志"
author: "抛出异常的爱"
date: "2008-12-17T20:07:04Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2008-12-17T20:07:04Z"
id: 296159
url: "https://loveexception.iteye.com/blog/296159"
---

昨天,有个需求要遍历子树,......
如果用贫血作...sql可达200行以上加了条件之后有可能达400
如果用充血作....代码很少不过要用到递归.....

还好oracle有connect by 

用贫血作了...
找到父结点以下所有的子节点(全家福)
select t.name ,level
from test t 
connect by prior t.name = t.parent
start with t.name='100001'


找到子结点的所有父节点(族谱)
select t.name ,level
from test t 
connect by prior  t.parent =t.name
start with t.name='100111'