问题描述
我需要一个特定的业务场景来为一个实体(不是PK)上的字段设置一个序列中的数字(序列必须是最小值和最大值之间的数字)
我定义了如下序列:
CREATE SEQUENCE MySequence
MINVALUE 65536
MAXVALUE 4294967296
从65536开始
由1
开始增加周期
开始
开始订单;
在Java代码中,我从这个序列中检索数字:
select mySequence.nextval从双
我的问题是:
如果我在事务中调用这个从双
选择mySequence.nextval,并且在另一个事务中同时调用同样的方法(并行请求),那么值返回的顺序是不同的?
不可能像从第一个事务读取未提交的值吗?
ç ause假设我没有使用序列和普通表格,我会自己增加序列,那么如果trasactinalitY是默认的READ COMMITTED,事务2将能够读取相同的值。
答案是否定的。
Oracle保证序列生成的数字不同。即使发出并行请求,RAC环境或回滚和提交也是混合的。
序列与事务无关。
使用CREATE SEQUENCE语句创建一个序列,该序列是
数据库对象,多个用户可以从中生成唯一的
整数。您可以使用序列自动生成主键
值。
序列号独立于表生成,因此同一个
序列可用于一个或多个表。可能
单个序列号似乎会被跳过,因为
它们是在一个事务中生成和使用的,最终将
回滚。此外,单个用户可能没有意识到其他用户是
从相同序列中绘制的。
I need for a particular business scenario to set a field on an entity (not the PK) a number from a sequence (the sequence has to be a number between min and max
I defined the sequence like this :
CREATE SEQUENCE MySequence
MINVALUE 65536
MAXVALUE 4294967296
START WITH 65536
INCREMENT BY 1
CYCLE
NOCACHE
ORDER;
In Java code I retrieve the number from the sequence like this :
select mySequence.nextval from dual
My question is :
If I call this "select mySequence.nextval from dual
" in a transaction and in the same time in another transaction same method is called (parallel requests) it is sure that the values returned by the sequence are different ?
Is not possible to have like read the uncommitted value from the first transaction ?
Cause let's say I would have not used sequence and a plain table where I would increment myself the sequence, then the transaction 2 would have been able to read same value if the trasactinalitY was the default "READ COMMITTED".
The answer is NO.
Oracle guarantees that numbers generated by sequence are different. Even if parallel requests are issued, RAC environement or rollback and commits are mixed.
Sequences has nothing to do with transactions.
这篇关于Oracle序列事务性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!