日期:2014-05-16  浏览次数:20452 次

掌握start with connect by应用:遍历邻接模型的树
邻接模型的树为--‘记录’中存有节点信息和父节点的标识id。
对于这样的树,遍历取得节点的目录结构是很容易的,只因为oracle提供了start with connect by方式。
start with:遍历的起点,可以有多个条件
connect by:确定上下(父子)级关系,可有多个条件
下面举例子,说明用法:
///////////////////////////////////[1]节点和叶子组成的树(路径)
select sys_connect_by_path(trim(f.function_name),';') 
from ep_sys_funccode_info f start with f.parent_code = '99999' 
connect by f.parent_code = prior f.function_code; 
////////////////////////////////////[2]叶子的树(路径)
select t1.code,t1.dir from (
select f.function_code code, sys_connect_by_path(trim(f.function_name),';') dir,f.node_type ty 
from ep_sys_funccode_info f start with f.parent_code = '99999' and f.function_name like '系统%' 
connect by f.parent_code = prior f.function_code 
) t1 where t1.ty = '1';