INCREMENT BY | 増分値 (デフォルト1) |
---|---|
START WITH | 初期値 (デフォルト1) |
MAXVALUE NOMAXVALUE |
最大値 (デフォルトNOMAXVALUE) |
MINVALUE NMINVALUE |
最少値(デフォルトNOMINVALUE) |
CYCLE NOCYCLE |
CYCLEの場合、最大値に達すると 最小値に戻り、順序値を生成 (デフォルトCYCLE) |
CACHE NOCACHE |
CACHEの場合、メモリ上に事前に順序値を生成 (デフォルトCACHE 20) |
SQL> create sequence test_seq 2 increment by 10 3 start with 100 4 maxvalue 9999 5 nocycle; Sequence created.
SQL> select test_seq.currval from dual;
select test_seq.currval from dual
*
ERROR at line 1:
ORA-08002: sequence TEST_SEQ.CURRVAL is not yet defined in this session
SQL> select test_seq.nextval from dual;
NEXTVAL
----------
100
SQL> select test_seq.nextval from dual;
NEXTVAL
----------
110
SQL> select test_seq.currval from dual;
CURRVAL
----------
110
SQL> insert into departments values (test_seq.nextval,'TEST',1); 1 row created. SQL> select * from departments; DEPT_ID DEPT_NAME LOC_ID ---------- ------------------------------ ---------- 10 Human Resources 1 20 Consulting 1 30 Sales 2 40 Engineering 2 50 Human Resources 1 60 International 100 DB 3 120 TEST 1 9 rows selected.
SQL> select test_seq.currval from dual; CURRVAL ---------- 120 SQL> insert into departments values (test_seq.nextval,'TEST','TEST'); insert into departments values (test_seq.nextval,'TEST','TEST') * ERROR at line 1: ORA-01722: invalid number SQL> select test_seq.currval from dual; CURRVAL ---------- 130
SQL> select test_seq.currval from dual; CURRVAL ---------- 130 SQL> insert into departments values (test_seq.nextval,'TEST',1); 1 row created. SQL> rollback; Rollback complete. SQL> select test_seq.currval from dual; CURRVAL ---------- 140