Sequence usage in Oracle:
Create table test
(Pid integer primary key,
Name varchar (20)
);
Select * from test;
Insert into test values (1, 'jack ');
Create sequence test_seq; -- create a sequence
Select test_seq.nextval from dual; -- add one after each use of the sequence
Select test_seq.currval from dual; -- query the value of the current sequence
Insert into test values (test_seq.nextval, 'Jack Or Duck? '); -- Sequence usage
Drop sequence test_seq; -- delete a sequence
Create sequence test_seq start with 8; -- specify the initial value of the sequence
Alter sequence test_seq minvalue 9; -- sets the minimum value of the sequence.
Alter sequence test_seq maxvalue 9999; -- sets the maximum value of the sequence.
Alter sequence test_seq increment by 1; -- sets the sequence step size.
Drop sequence test_seq_1;
Create sequence test_seq_1 start with 3 minvalue 1 maxvalue 30 increment by 1;
Select test_seq_1.nextval from dual;
Alter sequence test_seq_1 cycle;
Alter sequence test_seq_1 nocycle; -- disable the cyclic Value Function
Alter sequence test_seq_1 cache 10;
-- Set the sequence cache size. Note: The default value of the sequence cache is 20.
Create sequence test_seq_2 start with 1 minvalue 1 maxvalue 20 increment by 3;
Alter sequence test_seq_2 cycle;
-- The preceding statement reports an error: the Cache value must be smaller than the cycle value.
Alter sequence test_seq_2 increment by 2;
Alter sequence test_seq_2 cycle;
-- Error reported
Alter sequence test_seq_2 increment by 1;
Alter sequence test_seq_2 cycle;
-- Error reported
Alter sequence test_seq_2 maxvalue 21;
Alter sequence test_seq_2 cycle;
-- No error is reported.
-- Or modify
Alter sequence test_seq_1 cache 5;
-- Start with 1 and maxvalue 10 step 1 then 10 times cycle and bigger than 5