declare cursor nrow is select id,pid,dl from test1 order by id; crow test1%ROWTYPE;
function getsum(tp in char) return number is d number; i varchar2(10); cursor n is select id,dl from test1 where pid=tp; begin open n; fetch n into i,d; if n%FOUND then close n; return d*getsum(i); else close n; return 1; end if; end getsum; begin open nrow; fetch nrow into crow; while nrow%FOUND loop DBMS_OUTPUT.PUT_LINE(crow.id||' '||crow.pid||' '||getsum(crow.pid)); fetch nrow into crow; end loop; close nrow; end; ------试试,可以的话就给分哈。
数据插入临时表。
楼上的说法偶赞同。
1、存储过程是实现test1表中字段dl的递归。
存储过程中定义游标就可实现。
在循环一次以后:temp_test1.newdl=temp_test1.dl*test1.dl
谢谢,周一见。祝贺你升为四三角了。
TO:iamtalent(执著一生)
我是新手,简单的过程还成,这个吗,一个字‘难’。我会找点资料看看的。能给点具体点的东东吗??谢啦
cursor nrow is select id,pid,dl from test1 order by id;
crow test1%ROWTYPE;
function getsum(tp in char)
return number
is
d number;
i varchar2(10);
cursor n is select id,dl from test1 where pid=tp;
begin
open n;
fetch n into i,d;
if n%FOUND then
close n;
return d*getsum(i);
else
close n;
return 1;
end if;
end getsum;
begin
open nrow;
fetch nrow into crow;
while nrow%FOUND loop
DBMS_OUTPUT.PUT_LINE(crow.id||' '||crow.pid||' '||getsum(crow.pid));
fetch nrow into crow;
end loop;
close nrow;
end;
------试试,可以的话就给分哈。