db2 oracle 创建 序列

1、创建序列最小值1,最大值2147483647, 并 修改 从 500开始++
CREATE SEQUENCE "LXGZZS"."SEQ_COMMON" AS INTEGER
	MINVALUE 1 MAXVALUE 2147483647
	START WITH 1 INCREMENT BY 1
	CACHE 20 NO CYCLE NO ORDER;

ALTER SEQUENCE "LXGZZS"."SEQ_COMMON" RESTART WITH 500;


2、创建序列最小值是1 没有最大值,DB7.2以后才有sequence这个对象,创建的时候和oralce一样。

CREATE SEQUENCE seq_name AS INT 
START WITH 1 
INCREMENT BY 1 
MINVALUE 1 
NO MAXVALUE 
NO CYCLE 
NO CACHE
ORDER 

3、序列的使用

DB2中:
nextval for sequencename ,prevval for sequencename 
select nextval for seq_name from sysibm.sysdummy1;
select prevval for seq_name from sysibm.sysdummy1;
oracle中:
sequencename.nextval,sequencename.currval
select seq_name.nextval from dual;
select seq_name.currval from dual;
sysibm.sysdummy1是DB2内存中的一个特殊的表。


 

你可能感兴趣的:(db2 oracle 创建 序列)