当我创建一个序列seq_hehe,直接在insert里使用seq_hehe.nextVal,它是从2开始的。如果在创建序列之后做select,它的值就是从1开始。听明白了,我是创建完一个序列。直接用在insert里面。它的值是从2开始的。为什么会这样呢?

解决方案 »

  1.   

    序列是以事务为单位,即便事务没有成功,基数也会被分配
    create是该序列第一个事务,1被分配
      

  2.   


    你再试试,创建2个序列一样的,一个做insert 一个做select ,我试过了是一样的
      

  3.   


    create table hehehe(
    zheId number primary key,
    nima varchar2(50) not null
    );create sequence seq_ciao;
    create sequence seq_ciaos;insert into hehehe values(seq_ciao.nextval,'从几开始');
    select * from hehehe;select seq_ciaos.nextval from dual;--作弊可是无意义的。就这样的语句,就这样的效果,别笑我的命名
      

  4.   

    都是 序列名.nextval 用在插入就是2,直接查询就是1。
      

  5.   

    currentval和nextval 两个方法要搞清楚。
    跟事务有毛的关系,只要你调用了nextval它就向前进1. 不会后退。
      

  6.   

    你drop掉你的这个序列 再重新建任意序列,再插入一下表就正常了
      

  7.   

    还是楼主操作上有问题,insert也应该从1开始,是不是什么时候误操作已经把1占用了?
      

  8.   

    LZ 我找到答案了,请看
    http://docs.oracle.com/cd/E11882_01/server.112/e17118/statements_6015.htm#SQLRF01314
    这是11g r2的新特性
    Note on Using Sequences with Deferred Segments If you attempt to insert a sequence value into a table that uses deferred segment creation, the first value that the sequence returns will be skipped.
      

  9.   

    在线翻译上面一句话“注意:使用序列的延迟段(Deferred Segments)如果你尝试插入序列为一个表使用延迟部分创作,第一个值,返回的序列将被忽略。”
    这句话我暂时不理解。
      

  10.   

    Note on Using Sequences with Deferred Segments If you attempt to insert a sequence value into a table that uses deferred segment creation, the first value that the sequence returns will be skipped
    什么乱翻译器?
    应该是:在延迟段技术中使用序列应当注意如果你在尝试插入一个序列值到一个使用延迟段技术创建的表中,那么序列的第一个返回值将被跳过。