见下面几个语句 (请问为什么第三个语句插入的数据只有一条, where 和 connect by的区别):create table t1 as select rownum as id, rownum+1 as id2 from dual connect by level<=5;select * from t1create table t2 as select rownum as id, rownum+1 as id2 from dual connect by rownum <=5;select * from t2create table t3 as select rownum as id, rownum+1 as id2 from dual where rownum <=5;select * from t3
2 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
connect by 是oracle中特殊的递归查询的语法,多用于组织结构遍历、菜单树遍历等场景,如下面的一个功能菜单表,pid表示上级菜单的id,0表示无上级菜单,如果想查出顶级菜单下的所有菜单,可以用下面的写法:
id pid
1 0
2 1
3 1
4 2
5 3
select *from tstart with pid = 0connect by pid = prior id
你给的例子中,是connect by的一个特殊用法,用来产生指定行的一个虚拟表。
- 2 回答
- 0 关注
- 1460 浏览
添加回答
举报
0/150
提交
取消