PRIOR clause
The relationship between the parent record and its child records is expressed by the prior
keyword:
PRIOR child_id = parent_id
Interpreting start with … connnect by prior statements
The following sort-of-pseudo code demonstrates how a start with … connect by
statement might be interpreted.
declare
procedure RECURSE (rec in MATCHES_SELECT_STMT, parent_id IN field_type) is
begin
APPEND_RESULT_LIST(rec);
for rec_recurse in (select * from some_table) loop
if FULLFILLS_CONNECT_BY_CONDITION(rec_recurse.id, parent_id) then
RECURSE(rec_recurse,rec_recurse.id);
end if;
end loop;
end procedure RECURSE;
begin
for rec in (select * from some_table) loop
if FULLFILLS_START_WITH_CONDITION(rec) then
RECURSE(rec, rec.child);
end if;
end loop;
end;
Thanks to Frank Trenkamp who spotted an error in the logic in the above pseudo code and corrected it.
Thanks also to Abhishek Ghose who made me think about a better way to describe the logic.
TODO
With sys_connect_by_path
it is possible to show the entire path from the top level down to the 'actual' child
connect_by_root
, connect_by_isleaf
, connect_by_iscycle
Thanks
Thanks to Peter Bruhn, Jonathan Schmalze, Jeff Jones, Keith Britch and Fabian Iturralde who each pointed out an error or typo on this page.