oracle connect by start with
来源:互联网 发布:linux安全加固方案 编辑:程序博客网 时间:2024/05/10 20:37
select * from tb_menu m start with m.id=2 connect by prior m.parent= m.id;
找2的父节点,
select * from tb_menu m connect by prior m.id= m.parent start with m.id=2;找2的子节点
生成不间断的列
select rownum from dual connect by level < 10;
关于prior的理解,prior后面的字段就是父行,另外的字段来匹配父行,比如上面的第一个sql,m.paraent是父行,从id=2的子行开始,向上层次查找父记录中id字段是2的父行,第二个例子,id是父行,从id=2开始的父行开始,查找子行中parent=2的记录
对同层的记录进行排序
select employee_id,level,last_name,first_name from employees start with manager_id is null connect by manager_id= prior employee_id order siblings by last_name,first_name;
裁剪
不想看到last_name为‘B'及它的下级
select employee_id,level,last_name,first_name from employees start with manager_id is null connect by manager_id= prior employee_id and not(last_name='B') order siblings by last_name,first_name;
仅排除’B',还要包含它的下级
select employee_id,level,last_name,first_name from employees where not(last_name='B') start with manager_id is null connect by manager_id= prior employee_id order siblings by last_name,first_name;
在层次中生成路径名
select '/u01/emp'||sys_connect_by_path(last_name||','||first_name,'/') gen_path from employees start with manager_id is null connect by prior employee_id = manager_id;
辨认叶子节点
select last_name,frist_name,level,connect_by_isleaf is_leaf from employees start with manager_id is null connect by prior employee_id=manager_id;
查看节点的最高经理,中间的不显示
select last_name,first_name,level,connect_by_root last_name,connect_by_root first_name from employees where connect_by_isleaf=1 start with manager_id is null connect by prior employee_id = manager_id;
检查层次结构数据中的循环
select employee_id,manager_id,level,connect_by_iscycle is_cycle,last_name,first_name from employees start with last_name='kk' connect by nocycle manager_id = prior employee_id;
参考
http://www.cnblogs.com/linjiqin/archive/2013/06/24/3152674.html
- Oracle Connect By Start With
- oracle start with connect by
- oracle connect by start with
- Oracle Start With Connect By 的用法
- Oracle start with ... connect by prior 用法
- Oracle中start with...connect by prior
- Oracle start with...connect by prior用法
- Oracle Connect By Start With 用法
- Oracle递归查询 start with Connect By
- Oracle Connect By Start With 总结
- oracle 函数: start with ... connect by 使用方法
- Oracle start with connect by prior 用法
- oracle中start with connect by prior
- oracle 的 CONNECT BY 和START WITH
- oracle 递归 start with connect by level
- Oracle递归 Start with 和Connect By
- Oracle中connect by prior .... start with
- oracle start with connect by 用法
- 马一鸣AA小助手-1
- android studio 的神器--bitmap
- spark-parquet列存储之:文件存储细节之:RowWriteSupport和RecordWriter
- 基于Detours劫持360启动
- Getting Started with TLM-2.0
- oracle connect by start with
- dojo上传功能有用的文章
- Lua学习(六)-----函数
- 设计模式实例-单例
- 引用,其实不可以改变指向
- POJ2226 Muddy Fields【二分图最小点覆盖】
- 在Java继承中,非构造函数的方法的分析
- 大型免费千人视频聊天
- CSS系列2-定位2:浮动