简体   繁体   English

关注IBM DB2 NEXT VALUE

[英]IBM DB2 NEXT VALUE FOR concern

I am wondering when using the NEXT VALUE FOR does it lock the data area in the background? 我想知道什么时候使用NEXT VALUE FOR它会在后台锁定数据区吗? I want to make sure it does not create duplicate sequence numbers. 我想确保它不会创建重复的序列号。

For Db2 for i-Series, the reference documentation for sequence is here. 对于i-Series的Db2, 序列的参考文档在这里。

The reference documentation (for Db2-LUW) has what you need. 参考文档(适用于Db2-LUW)具备您所需的功能。

When a value is generated for a sequence, that value is consumed, and the next time that a value is requested, a new value will be generated. 为序列生成值时,将消耗该值,并在下次请求值时生成新值。 This is true even when the statement containing the NEXT VALUE expression fails or is rolled back. 即使包含NEXT VALUE表达式的语句失败或回滚,也是如此。

However, if there are multiple instances of a NEXT VALUE expression specifying the same sequence name within a query, the counter for the sequence is incremented only once for each row of the result, and all instances of NEXT VALUE return the same value for a row of the result. 但是,如果NEXT VALUE表达式的多个实例在查询中指定相同的序列名称,则序列的计数器仅对结果的每一行递增一次,并且NEXT VALUE的所有实例为行返回相同的值结果。

Notice that Db2 does not guarantee sequential numbers will be returned. 请注意,Db2不保证将返回序列号。 So if your transaction rolls back, any previously consumed value from the sequence will not be returned in future - as long as the sequence is not reset at least. 因此,如果您的事务回滚,则序列中以前消耗的任何值将来都不会返回 - 只要序列至少不重置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM