見(jiàn)下面幾個(gè)語(yǔ)句 (請(qǐng)問(wèn)為什么第三個(gè)語(yǔ)句插入的數(shù)據(jù)只有一條, where 和 connect by的區(qū)別):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貢獻(xiàn)2036條經(jīng)驗(yàn) 獲得超8個(gè)贊
connect by 是oracle中特殊的遞歸查詢(xún)的語(yǔ)法,多用于組織結(jié)構(gòu)遍歷、菜單樹(shù)遍歷等場(chǎng)景,如下面的一個(gè)功能菜單表,pid表示上級(jí)菜單的id,0表示無(wú)上級(jí)菜單,如果想查出頂級(jí)菜單下的所有菜單,可以用下面的寫(xiě)法:
id pid
1 0
2 1
3 1
4 2
5 3
select *from tstart with pid = 0connect by pid = prior id
你給的例子中,是connect by的一個(gè)特殊用法,用來(lái)產(chǎn)生指定行的一個(gè)虛擬表。
- 2 回答
- 0 關(guān)注
- 1545 瀏覽
添加回答
舉報(bào)
0/150
提交
取消