之前創建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)