没法解决,不能使sequence回退,除非重建

解决方案 »

  1.   

    难道真的没有办法,是不是insert时尽量减少错误啊
      

  2.   

    不是用触发器,如果出错就保存出错时的seq值,下次插入时不用seq了不要用cache,否则重启oracle也会跳
      

  3.   

    to panet:
      如果我保存出错,则seq增加1,而此时我退出程序了,则序列还是递增1了,下次操作时还是出现跳空现象,难道这个问题真的不能解决了
      

  4.   

    那只好用一个包实现序号办法.
    CREATE OR REPLACE PACKAGE pkg_test
    AS
       t_id number:=1;
    END pkg_test;
    /create trigger name_tri
    before insert on table
    for each row
    begin
    :new.id:=t_id;
    t_id:=t_id+1;
    exception
      when others then 
        t_id:=t_id-1;
    end;
    /
    看是否行?
      

  5.   

    可能吗,你的存储过程怎么写的?
    CREATE OR REPLACE XXX AS
    BEGIN
      AA:=0;
     BEGIN
      INSERT INTO AAA VALUES(BBB。CURRVAL);
     EXCEPTION WHEN OTHERS THEN 
          AA:=1;
           GOTO DDD
     END;
    《DDD》
       IF AA=1 THEN 
          NULL;
       ELSE
          BBB。NEXTVAL;
       END IF;
    END;
      

  6.   

    你的包有什么用?
    每一个新的session里面,初始t_id都是1,那不要出现成堆的重复记录了
      

  7.   

    使用  maohaisheng() ( ) 的方法,实际开发都是这种方法
      

  8.   

    我最会处理这个问题了,不过我处理的都是OO4O中出现的状态,不知是否满足你的要求
    OO4O中,默认使用了cache,这是和数据库中的cache不同的,所以这样做:
    Public Function getSequence(sName As String) As Long
    On Error GoTo errHandle''''''''''''''''''
    '' 取得sequence值
    ''
    ''''''''''''''''''
    SQL = "select " & sName & ".nextval from dual"
    Set oraRs = oraDatabase.dbcreatedynaset(SQL, &H4&)getSequence = oraRs.Fields("nextval").value
    Exit Function
    errHandle:
        getSequence = -1
    End Function这里面最重要的就是&H4&
    如果对的话一定要给我分噢:P
      

  9.   

    写一个用于执行Insert语句的过程,
    在过程中使用事务。程序中调用该过程时,将要插入的数据传给过程。
      

  10.   

    to tuidler
       INSERT INTO AAA VALUES(BBB。CURRVAL);
       你这插的是序列的当前值,那不是重复了吗,即使执行成功,数据重复有啥意思。
       不是很明白你的存储过程
      

  11.   

    哎,我那个只是个大致的意思,你既然是要保持一个唯一的号,你的那个列没有主键吗,
    否则你怎么保持那个值是递增的。如果有重复值,就要跳出报错,也就是将那个NULL的地方,
    改成一个MESSAGE就是了。
      

  12.   

    要么就不要用序列了,再用一个表来保存这个值,每当要插入的时候,从这个表里取出当前值,如果INSERT成功,就同时递增那个表里的那个值,否则就不递交。则你每次INSERT的这个值也就肯定是递增的。当然你的那个列应该建主键的,来防止重复记录。
    方法很多,不要局限在一点上。
      

  13.   

    CREATE OR REPLACE INS_TAB AS
      ID NUMBER;
    BEGIN
      INSERT INTO TAB VALUES(SEQ.CURRVAL);
      SEQ.NEXTVAL; 
    EXCEPTION 
      WHEN OTHERS THEN 
        RETURN ERROR HANDLE
    END;
      

  14.   

    Ø If the NOCACHE option is used during creation the numbers won't be cached in the SGA and sequential numbers will result. However, any numbers referenced by the NEXTVAL function will be lost if the transaction is rolled back before completion thus causing a break in sequential numbering.Ø CACHE will cache the specified number of sequence values into the buffers in the SGA. This speeds access, but all cached numbers are lost when the database is shutdown.Ø If you are using the Parallel Server option in parallel mode and you specify the ORDER option, sequence values are never cached, regardless of whether you specify the CACHE parameter or the NOCACHE option.
      

  15.   

    //如果出错,则调用一下程序块可以解决
    declare
    n number(10);
    tsql varchar2(100);
    begin
    select my_seg.nextval into n from dual;
    n:=-1;
    tsql:='alter sequence my_seg increment by'|| n;//把increment设为负数
    execute immediate tsql;
    select my_seg.nextval into n from dual;//达到减一的效果
    tsql:='alter sequence my_seg increment by 1';//恢复原来的increment参数值
    execute immediate tsql;
    end;
    /
      

  16.   

    用GUID怎么样?没有重复,又没有跳号,只是占用存储空间大一点。
      

  17.   

    呵呵,用MS的SQLSERVER2000就不会有这种烦人的事发生了。