Oracle创建Sequence时Order/NoOrder选项

问题

Oracle创建Sequence时会有Order/NoOrder两个选项,那么到底什么场景用到Order,什么场景又用到NoOrder呢?

官方文档

ORDER 
    guarantees that sequence numbers are generated in order of request. 
    You may want to use this option if you are using the sequence 
    numbers as timestamps. Guaranteeing order is usually not important 
    for sequences used to generate primary keys. 

NOORDER 
    does not guarantee sequence numbers are generated in order of 
    request. 

    If you omit both the ORDER and NOORDER options, Oracle chooses 
    NOORDER by default. Note that the ORDER option is only necessary to 
    guarantee ordered generation if you are using Oracle with the 
    Parallel Server option in parallel mode. If you are using exclusive 
    mode, sequence numbers are always generated in order. 

分析

Order:

保证序列号按请求顺序产生。如果想以序列号作为timestamp(时间戳)类型的话,可以采用该选项。对于将序列用于生成主键来说,约定顺序通常并不重要。

NOORDER: 
此选项跟Order相对应,并不按照请求的顺序进行生成。

举例

双CPU对同一个oracle DB 中的 ABC sequence申请序号时, 这时就有两个请求A和B,假设A请求在前B在后, 现在 ABC序列中的值为9。 如果添加了ORDER选项,那么一定是A请求到9, B请求到10。但如果没有添加此选项,则有可能B请求到9, A请求到 10。

总结

无论使用哪个选项,sequence中生成的数据都是唯一的。因此,我们可以得出结论,在用sequence中的数据作为ID时,无论选择哪个选项都能确保ID的唯一性。但如果,用sequence中的数据作为时间戳时,则需要使用Order选项,确保先到的请求时钟排序在前面。

 

转载原文地址:https://www.cnblogs.com/damens/p/6460606.html

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值