我该如何解决ORA-04007

时间:2013-09-25 13:38:49

标签: sql oracle oracle11g

我正在使用toad for oracle 11g,我尝试使用UI(用户界面)alter sequence

我想更改currval

我阻止了这个错误:

  

ORA-04007:MINVALUE不能超过当前值

1 个答案:

答案 0 :(得分:4)

您不直接更改序列的伪列的currval值 - 每次引用序列的nextval伪列时,其值都会更改。听起来更像是要发出alter sequence语句来更改其minvalue参数。

如果序列的当前值小于您尝试更改为的minval,则会引发错误。您至少有两个选项可以完成它:

  1. 使用minvalue参数
  2. 的新值完全重新创建序列
  3. 更改incremet by值,生成下一个值,更改minval参数,然后更改increment by值。
  4. 以下是一个例子:

    create sequence seq
    increment by 1
    minvalue 1
    
    sequence SEQ created.
    
    -- trying to change minvalue
    alter sequence seq 
      minvalue 5
    
    SQL Error: ORA-04007: MINVALUE cannot be made to exceed the current value
    
    
    select seq.nextval
      from dual
    
    NEXTVAL
    ------------
             1 
    
    -- alter increment by
    alter sequence seq
       increment by 4
    
    select seq.nextval
      from dual
    
    NEXTVAL
    ----------
           5 
    
    -- altering minvalue
    alter sequence seq 
      minvalue 5
    
    sequence SEQ altered.
    
    -- change increment by to 1 as it was before
    alter sequence seq
       increment by 1
    
    sequence SEQ altered.