Oracle 序列 CACHE 值必须小于 CYCLE 值的解决方法

Oracle Sequence Cache限制
本文介绍在Oracle数据库中创建Sequence时,如何正确设置CACHE值避免错误。通过实例解析CACHE值的计算方法及其与INCREMENT BY和MAXVALUE的关系。

 

之前创建sequence时碰到一个问题, 当我使用了cache时总是提示CACHE 值必须小于 CYCLE 值,查了下文档,找到这么一个公式

 

文档的大概意思是cache的值必须要小于通过这个公式计算得到的值,举例:

这条语句会报错,带入公式有ceil(200-1)/abs(20) = 10,所以cache的最大值只能是10,大于10会报错

create sequence emp_empno_seq
increment by 20
start with 1
maxvalue 200
cycle
cache 20;

 将cache的值修改为<=10,即可正常创建

附:文档解释

Specify how many values of the sequence Oracle preallocates and keeps in memory for faster access. This integer value can have 28 or fewer digits. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle. You cannot cache more values than will fit in a given cycle of sequence numbers. Therefore, the maximum value allowed for CACHE must be less than the value determined by the following formula:

 (CEIL (MAXVALUE - MINVALUE)) / ABS (INCREMENT)


 

转载于:https://www.cnblogs.com/tele-share/p/7702145.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值