? ? 绝对值必须小于MAXVALUE与MINVALUE的差异(如非在此区间报错:ORA-04005: INCREMENT must be less than MAXVALUE minus MINVALUE)。 ? ? 假设这个值是负的,则该序列下降。假设该值为正。则序列上升。假设省略此子句。则间隔缺省为1。 START WITH指定要产生的第一个序列号。
这个整数值能够最多28位数字。MINVALUE必须<=START WITH的值和必须小于MAXVALUE。 ? ? 如此处不符,报:ORA-04006: START WITH cannot be less than MINVALUE。不指定此參数时,默认是1. NOMINVALUE:指定NOMINVALUE来表示递增的序列最小值为1,递减序列为负10的26次方。
这是默认的。 CACHE :指定数据库为序列预分配多少个值放在内存中以便更快訪问。这个整数值能够最多28位数字。该參数最小值为2; ? ? 这个值必须小于一个CYCLE循环的数(比方从1-100是一个循环。CACHE要小于100,不然可能 一次CACHE的值要有反复的会出错。 ? ? 报错是:ORA-04013: number to CACHE must be less than one cycle)。
[email?protected] bys3>insert into test values(test_seq.nextval,‘seqtest‘); --使用INSERT语句调用序列 ? ? 1 row created. ? ? [email?protected] bys3>select * from test; ? ? OBJECT_NAME STATUS ? ? ------------ ------- ? ? 10 seqtest [email?protected] bys3>insert into test values(test_seq.currval,‘seqtest‘); ? ? 1 row created. ? ? [email?protected] bys3>select * from test; ? ? OBJECT_NAME STATUS ? ? ------------ ------- ? ? 10 seqtest ? ? 10 seqtest [email?protected] bys3>insert into test(object_name) select test_seq.nextval from dual; --使用INSERT子语调用序列 ? ? 1 row created. ? ? [email?protected] bys3>select * from test; ? ? OBJECT_NAME STATUS ? ? ------------ ------- ? ? 10 13 ? ? 10 16 ? ? 4
[email?protected] bys3>update test set status=test_seq.nextval; --使用UPDATE语句调用序列 ? ? 2 rows updated. ? ? [email?protected] bys3>select * from test; ? ? OBJECT_NAME STATUS ? ? ------------ ------- ? ? 10 13 ? ? 10 16 [email?protected] bys3>delete test where status=test_seq.currval; --DELETE中不能使用sequence做条件 ? ? delete test where status=test_seq.currval ? ? * ? ? ERROR at line 1: ? ? ORA-02287: sequence number not allowed here 利用解发器自己主动为表插入递增序列:---相似自增字段的作用 建解发器代码为: ? ? create or replace trigger tri_test_id ? ? before insert on test --test 是表名 ? ? for each row ? ? declare ? ? nextid number; ? ? begin ? ? IF :new.testid IS NULL or :new.testid=0 THEN --DepartId是列名 ? ? select seq1.nextval --seq1是提前创建好的序列的名字 ? ? into nextid from sys.dual; ? ? :new.testid:=nextid; ? ? end if; ? ? end tri_test_id;