Sunday, January 3, 2016

How to modify or create a sequence with a new value

How to modify or create a sequence with a new value:-


Say the name of the sequence is SEQ_SUBSCRIPTION_NUMBER or SEQ__SOURCE_COMPANY_ID.


Check the current value of the sequence:


select  SEQ_SUBSCRIPTION_NUMBER.nextval from dual;


19154970


Check the current value of the sequence:


select  SEQ__SOURCE_COMPANY_ID.nextval from dual;


19005240


Alter the sequence by incrementing with positive or negative number as requred,this will reset the sequence.


 ALTER SEQUENCE TAPET.SEQ__SOURCE_COMPANY_ID increment BY -97250085 ;

 

 ALTER SEQUENCE TAPET.SEQ__SOURCE_COMPANY_ID increment BY 1

 

 select  SEQ__SOURCE_COMPANY_ID.nextval from dual;

 

 

 106483655


Now say you have to modify the sequence to some new starting value.

 

 8074950

 

 8074950


In that case drop and recreate the sequence with that starting value:

 

 DROP SEQUENCE TAPET.SEQ__SOURCE_COMPANY_ID;


CREATE SEQUENCE TAPET.SEQ_SUBSCRIPTION_NUMBER

  START WITH 8074950

  INCREMENT BY 1

  MAXVALUE 308999999

  MINVALUE 8074950

  NOCYCLE

  CACHE 20;

No comments: