1、序列定义
ORACLE:
CREATE SEQUENCE <sequence_name>
INCREMENT BY <integer>
START WITH <integer>
MAXVALUE <integer> / NOMAXVALUE
MINVALUE <integer> / NOMINVALUE
CYCLE / NOCYCLE
CACHE <#> / NOCACHE
ORDER / NOORDER;
DB2:
CREATE SEQUENCE <sequence-name>
AS data-type 默认 As Integer
START WITH <numeric-constant>
INCREMENT BY <numeric-constant> 默认 INCREMENT BY 1
MINVALUE <numeric-constant> | NO MINVALUE 默认 NO MINVALUE
MAXVALUE <numeric-constant> | NO MAXVALUE 默认 NO MAXVALUE
NO CYCLE | CYCLE 默认 NO CYCLE
CACHE <numeric-constant> | NO CACHE 默认 CACHE 20
NO ORDER | ORDER 默认 NO ORDER
2、序列取值
取下一个值:
ORACLE: 序列.NEXTVAL
DB2: NEXTVAL FOR 序列 或 NEXT VALUE FOR 序列
取当前值:
ORACLE: 序列.CURRVAL
DB2: PREVIOUS VALUE FOR 序列 或 PREVVAL FOR 序列
3、序列设置开始值
ORACLE:取得下一个值;先设置步长(下一个值 与 设置的开始值之间差);取得下一个值;再把步长修改成原来值
DB2:ALTER SEQUENCE 序列名 RESTART WITH 下一值
3、修改
ORACLE:
修改最大值 ALTER SEQUENCE <sequence_name> MAX VALUE <integer>
修改最小值: ALTER SEQUENCE <sequence_name> MIN VALUE <integer> (此值需要比当前值小)
修改步长: ALTER SEQUENCE <sequence_name> INCREMENT BY <integer>;
修改CACHE值: ALTER SEQUENCE <sequence_name> CACHE <integer> | NOCACHE
修改循环属性: ALTER SEQUENCE <sequence_name> <CYCLE | NOCYCLE>
修改排序属性:ALTER SEQUENCE <sequence_name> <ORDER | NOORDER>
DB2:
修改最大值 ALTER SEQUENCE <sequence_name> MAX VALUE <numeric-constant> | NO MAXVALUE
修改最小值: ALTER SEQUENCE <sequence_name> MIN VALUE <numeric-constant> | NO MINVALUE (此值需要比当前值小)
修改步长: ALTER SEQUENCE <sequence_name> INCREMENT BY <numeric-constant>;
修改CACHE值: ALTER SEQUENCE <sequence_name> CACHE <numeric-constant> | NO CACHE
修改循环属性: ALTER SEQUENCE <sequence_name> <CYCLE | NO CYCLE>
修改排序属性:ALTER SEQUENCE <sequence_name> <ORDER | NO ORDER>
从新计数: ALTER SEQUENCE <sequence_name> RESTART | RESTART WITH <numeric-constant>
3、DROP
ORACLE: DROP SEQUENCE <sequence_name>;
DB2: DROP SEQUENCE <sequence_name>;