我们正在将应用程序从Oracle迁移到DB2。这是一个批处理工作。有一个排序逻辑,在处理之前为条目分配id:
保留序列范围
选择MY_SEQUENCE.nextval; // range_start;
改变序列MY_SEQUENCE增量RANGE_SIZE;
选择MY_SEQUENCE.nextval;
改变序列MY_SEQUENCE增加1;
选择MY_SEQUENCE.nextval; // range_end;
通过内存递增值从一个范围内分配ID:
表示id = range_start:range_end do
这在Oracle中运行良好,但在DB2中给出了意想不到的结果。
在Oracle中:
DROP SEQUENCE MY_SEQUENCE;
CREATE SEQUENCE MY_SEQUENCE MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 50000 NOORDER NOCYCLE ;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 1;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 2;
ALTER SEQUENCE MY_SEQUENCE INCREMENT BY 100000;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 100002;
ALTER SEQUENCE MY_SEQUENCE INCREMENT BY 1;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 100003;
在DB2中:
DROP SEQUENCE MY_SEQUENCE;
CREATE SEQUENCE MY_SEQUENCE AS DECIMAL(27 , 0) START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 999999999999999999999999999 NO CYCLE CACHE 50000 NO ORDER;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 1;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 2;
ALTER SEQUENCE MY_SEQUENCE INCREMENT BY 100000;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 150000;
ALTER SEQUENCE MY_SEQUENCE INCREMENT BY 1;
SELECT MY_SEQUENCE.NEXTVAL FROM DUAL; // 5000050001;
我认为150000可以用CACHE大小来解释。但是我还不知道5000050001的价值。任何帮助都非常感谢。
注意:
答案 0 :(得分:0)
将序列改为NO CACHE解决了这个问题。