declare
maxl number;
idnew number;
begin
for t in (select id from t2) loop
select max(level) ll into maxl from t1 start with id=t.id connect by prior pid=id;
select id into idnew from
(select level ll, id,pid from t1 start with id=t.id connect by prior pid=id)
where ll=maxl-1;
update t2 set id=idnew where id=t.id;
end loop;
commit;
end;[@more@]
maxl number;
idnew number;
begin
for t in (select id from t2) loop
select max(level) ll into maxl from t1 start with id=t.id connect by prior pid=id;
select id into idnew from
(select level ll, id,pid from t1 start with id=t.id connect by prior pid=id)
where ll=maxl-1;
update t2 set id=idnew where id=t.id;
end loop;
commit;
end;[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7312700/viewspace-1002636/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7312700/viewspace-1002636/
本文介绍了一个使用PL/SQL编写的更新子程序示例。该子程序通过连接查询从两个表中获取最大层级的数据,并更新另一个表中的ID字段。此过程涉及声明变量、循环遍历记录集及执行嵌套查询。
2285

被折叠的 条评论
为什么被折叠?



