木曜日, 12月 04, 2008

START WITH and CONNECT BY in Oracle SQL

START WITH and CONNECT BY in Oracle SQLについて、René Nyffenegger's collection of things on the webにそのpseude codeが乗せてあって、分かり易いですね。


for rec in (select * from some_table) loop
if FULLFILLS_START_WITH_CONDITION(rec) then
RECURSE(rec, rec.child);
end if;
end loop;

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;

0 件のコメント: