请大家帮我看一下,序列的初期值是1,为什么想表中插入的结果变成了2?我觉得应该是1才对呀!
代码:
drop table tmp;
create table tmp
(
next number,
curr number
);drop sequence testseq;
create sequence testseq start with 1;insert into tmp(next,curr) values(testseq.nextval,testseq.currval);select * from tmp;结果:
      NEXT       CURR
---------- ----------
         2          2

解决方案 »

  1.   


    --你在执行插入语句前 执行了其他跟序列有关的操作吧?
    scott@YPCOST> create table tmp
      2  (
      3  next number,
      4  curr number
      5  );Table created.scott@YPCOST> create sequence testseq start with 1;Sequence created.scott@YPCOST> insert into tmp(next,curr) values(testseq.nextval,testseq.currval);1 row created.scott@YPCOST> select * from tmp;      NEXT       CURR
    ---------- ----------
             1          1
      

  2.   

    直接把上面的代码拷到PL/SQL的命令窗口执行的,在【create sequence testseq start with 1;】和【insert into tmp(next,curr) values(testseq.nextval,testseq.currval);】之间没有任何操作。
      

  3.   

    我也是这样啊
    create sequence testseq start with 1 increment by 1 nocache;
    你这样建序列看看
      

  4.   

    [create sequence testseq start with 1 increment by 1 nocache;]这样写在我这里还是不对,结果还是一样的。我用的数据库是oracle11g,执行环境是PL/SQL Developer 8.0,应该是环境配置的问题吧
      

  5.   

    下面这2种写法,用其中任意一种结果就对了。
    1.【create sequence testseq start with 1;】->【create sequence myseq minvalue 0;】
      ->zhuomingwang,不知道你的环境默认的minvalue值是多少?是零吗?
    2.【insert into tmp(next,curr) values(testseq.nextval,testseq.currval);】->
      【insert into tmp(next,curr) values(123,456);
        insert into tmp(next,curr) values(testseq.nextval,testseq.currval);】
      ->不知道为什么向表中插入一条数据后,再用序列插入就对了
      

  6.   

    建一个新的sequence,名字不要与以前的重复,这样就可以了!
      

  7.   

    to:BOBO12082119,试过了,也不行。但是如果表中已经有一条其他数据了,再进行序列值的插入,结果就没问题了。所以我觉得是不是我的DB建的有问题啊。
    create table tmp
    (next number
    );
    create sequence testseq start with 1;
    insert into tmp(next) values(123);
    insert into tmp(next) values(testseq.nextval);
    insert into tmp(next) values(testseq.nextval);
    select * from tmp;
    结果:
      NEXT
    ----------
    123
      1
      2