日期:2014-05-17 浏览次数:20755 次
declare cursor my_cur is select t.rowid row_id,t.ID1,t.NUM1 from table1 t order by 1; v_count number; v_j number; v_pid number; begin v_count:=0; v_j:=1; v_pid:=0; for row_t in my_cur loop if (v_pid=row_t.NUM1) then begin update table1 set NUM2=v_j where rowid=row_t.row_id; end; else begin v_j:=v_j+1; update table1 set NUM2=v_j where rowid=row_t.row_id; v_pid:=row_t.NUM1; end; end if; v_count:=v_count+1; if (v_count>=2000) then commit; v_count:=0; end if; end loop; commit; end; /
------解决方案--------------------
cursor myCur is select * from test;
oneRow test%rowtype;
flag1 number;
flag2 number;
flag3 number;
begin
flag1:=0;
flag2:=-1;
flag3:=0;
open myCur;
fetch myCur into oneRow;
while(myCur%found)
loop
if flag2=-1 then
select num1 into flag2 from test where id=oneRow.id;
flag1:=flag1+1;
UPDATE test set num2=flag1 where id=oneRow.id;
else
select num1 into flag3 from test where id=oneRow.id;
if flag3<>flag2 then
flag1:=flag1+1;
end if;
flag2:=flag3;
UPDATE test set num2=flag1 where id=oneRow.id;
end if;
fetch myCur into oneRow;
end loop;
close myCur;
------解决方案--------------------