I tried to find some informations about connect by "engine". I found this post: Confusion with Oracle CONNECT BY
User krokodilko answered and says:
The analyze of the last query:
select level from dual connect by rownum<10;
I leave to you as a homework assignment.
So i tried to do exactly as described to query
Select rownum from dual connect by rownum < 3
And here's my "work":
CREATE TABLE step1 AS
SELECT 1 "LEVEL" FROM dual;
SELECT * FROM step1;
create table step2 as
SELECT 2 "LEVEL" from dual
JOIN step1 "PRIOR" on rownum <=3;
SELECT * FROM step2;
create table step3 as
select 3 "LEVEL" from dual
join step2 "PRIOR" on rownum <=3;
SELECT * FROM step3;
create table step4 as
select 4 "LEVEL" from dual
join step3 "PRIOR" on rownum <=3;
SELECT * FROM step4;
But last SELECT still returns rows. Am I misunderstood something? Every time i Select LEVEL + 1 "LEVEL" it has rownum = 1 so it's always true. So am i failed steps?
CONNECT BY
. It's part of the SQL standard, unlikeCONNECT BY
. – ImbroglioCONNECT BY
queries and recursive CTE queries work differently:CONNECT BY
works on individual rows, while recursive CTE works on sets. This has various implications, especially to the definition and behavior of cycles. Second,CONNECT BY
is much faster than recursive queries (the cost of recursive queries being much more flexible), so - when aCONNECT BY
solution does exist - it may be preferred. Third,CONNECT BY
offersCONNECT_BY_ISLEAF
; that can be cloned in recursive CTE, but not easily. – Trost