drop 掉
重新创建不行么?

解决方案 »

  1.   

    你在pl/sql中编辑的时候应该view sql一下,就知道了它的处理也要至少传入三个参数
    1、sequence_name;2、nextval;3、increment by
    然后执行循环,每次查找序列的nextval,直到序列的currval等于设置值才结束
      

  2.   

    pl/sql是通过一个循环来改变下一个值的,你可以参照一下处理!-- Alter sequence
    alter sequence SP_TEST 
    increment by 1
    cache 20;
    -- Modify the last number 
    alter sequence SP_TEST increment by 2 nocache;
    select SP_TEST.nextval from dual;
    alter sequence SP_TEST increment by 1 nocache;
    declare
      LastValue integer;
    begin
      loop
        select SP_TEST.currval into LastValue from dual;
        exit when LastValue >= 1 - 1;
        select SP_TEST.nextval into LastValue from dual;
      end loop;
    end;
    /
    alter sequence SP_TEST increment by 1 cache 20;
      

  3.   

    谢谢各位。现在我想先从sys.obj$、sys.seq$等表中取到SEQ的基本数据保存下来,然后删除,然后重建,SF如下:
    create or replace function SF_SET_SEQ_NEXTVAL2(vcSeqName in varchar2, lNextVal in number) return number is
      Result number;
      lMinVal number;
      lMaxVal number;
      lIncVal number;            
      lCycle number;
      lOrder number;      
      lCache number;
      sCycle varchar2(10);
      sOrder varchar2(10);
      sCache varchar2(10);   
    begin          
          -- 悵湔橾腔SEQ統杅         
          select s.increment$, s.minvalue, s.maxvalue, s.cycle#, s.Order$, s.cache 
                 into lIncVal, lMinVal, lMaxVal, lCycle, lOrder, lCache
            from sys.obj$ o, sys.seq$ s, sys.user$ u
            where u.name = sys.login_user() and
                  u.user# = o.owner# and
                  o.name = upper(vcSeqName) and
                  o.obj# = s.obj#;
          if lCycle = 0 then sCycle := 'nocycle'; else sCycle := 'cycle'; end if;
          if lOrder = 0 then sOrder := 'noorder'; else sOrder := 'order'; end if;
          if lCache <= 0 then 
             sCache := 'nocache';
          else 
             sCache := 'cache '||lCache;
          end if;
          
          -- 刉壺SEQ
          Execute immediate 'drop sequence '||upper(vcSeqName)||';';
          
          -- 笭膘SEQ
          Execute immediate
          'create sequence '||vcSeqName||' minvalue '||lMinVal||' maxvalue '||lMaxVal||' start with '||lNextVal||' increment by '||lIncVal||' '||sCycle||' '||sOrder||' '||sCache||';';
      Result := 0;
      return(Result);
    end SF_SET_SEQ_NEXTVAL2;但是编译的时候取报“必须指明标识符sys.obj$”,我改成其它表名试了试可以,难道在存储过程中不能使用sys.obj$吗?