日期:2014-05-17  浏览次数:20636 次

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

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

------解决方案--------------------
你drop掉你的这个序列 再重新建任意序列,再插入一下表就正常了
------解决方案--------------------
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.


------解决方案--------------------
也就是11gr2 默认创建表是使用延时段创建,在第一次插入的时候才真正创建表。