際際滷

際際滷Share a Scribd company logo
1DR. GIRIJA NARASIMHAN
Part 7- Alter Sequence
2
DR. GIRIJA NARASIMHAN
Use the ALTER SEQUENCE statement to change the
increment,
minimum and maximum values,
cached numbers,
and behavior of an existing sequence.
This statement affects only future sequence numbers.
SQL> alter sequence seq1 start with 1001;
alter sequence seq1 start with 1001
*
ERROR at line 1:
ORA-02283: cannot alter starting sequence number
SQL> alter sequence seq1 increment by 2;
Sequence altered.
SQL> select seq1.nextval from dual;
NEXTVAL
----------
1001
SQL> select seq1.nextval from dual;
NEXTVAL
----------
1003
If you change the INCREMENT BY value
before the first invocation of NEXTVAL, some
sequence numbers will be skipped.
Therefore, if you want to retain the original
START WITH value, you must drop the
sequence and re-create it with the original
START WITH value and the new INCREMENT BY
value.
create sequence seq1
START WITH 1000
INCREMENT BY 1
NOCACHE
maxvalue 1005
minvalue 1000
cycle;
DR. GIRIJA NARASIMHAN
Oracle Database performs some validations. For example, a new
MAXVALUE cannot be imposed that is less than the current
sequence number.
SQL> select seq1.currval from dual;
CURRVAL
----------
1003
SQL> alter sequence seq1 maxvalue 1002;
alter sequence seq1 maxvalue 1002
*
ERROR at line 1:
ORA-04009: MAXVALUE cannot be made to be less than the current value
DR. GIRIJA NARASIMHAN
http://www.slideshare.net/nbgirija

More Related Content

Part 7 alter sequence modified

  • 1. 1DR. GIRIJA NARASIMHAN Part 7- Alter Sequence
  • 2. 2 DR. GIRIJA NARASIMHAN Use the ALTER SEQUENCE statement to change the increment, minimum and maximum values, cached numbers, and behavior of an existing sequence. This statement affects only future sequence numbers.
  • 3. SQL> alter sequence seq1 start with 1001; alter sequence seq1 start with 1001 * ERROR at line 1: ORA-02283: cannot alter starting sequence number SQL> alter sequence seq1 increment by 2; Sequence altered. SQL> select seq1.nextval from dual; NEXTVAL ---------- 1001 SQL> select seq1.nextval from dual; NEXTVAL ---------- 1003 If you change the INCREMENT BY value before the first invocation of NEXTVAL, some sequence numbers will be skipped. Therefore, if you want to retain the original START WITH value, you must drop the sequence and re-create it with the original START WITH value and the new INCREMENT BY value. create sequence seq1 START WITH 1000 INCREMENT BY 1 NOCACHE maxvalue 1005 minvalue 1000 cycle; DR. GIRIJA NARASIMHAN
  • 4. Oracle Database performs some validations. For example, a new MAXVALUE cannot be imposed that is less than the current sequence number. SQL> select seq1.currval from dual; CURRVAL ---------- 1003 SQL> alter sequence seq1 maxvalue 1002; alter sequence seq1 maxvalue 1002 * ERROR at line 1: ORA-04009: MAXVALUE cannot be made to be less than the current value DR. GIRIJA NARASIMHAN