日期:2014-05-16  浏览次数:20548 次

Oracle 根据序列已有最大值自动生成累加序列
CREATE OR REPLACE Procedure Test As
  v_Sn Integer;

Begin

  Select Max(Sn) Into v_Sn From Postcard_Print;
  For i In (Select Rowid Row_Id From Postcard_Print Where Sn Is Null) Loop
    v_Sn := v_Sn + 1;
    Update Postcard_Print Set Sn = v_Sn Where Rowid = i.Row_Id;
  Commit;
  End Loop;
  Commit;
End;

?说明:

?????? Postcard_Print为需要加入序列的表名;

?????? v_Sn为设置的累加变量;

?????? Sn为序列的字段;

1 楼 zhaobin87 2012-08-02