Tuesday, September 6, 2011

Incrementing sequence value

How can we set sequence value to a higher one? Say for example the current value of our sequence is 100 and we need to set this to 250, how can we accomplish this?

SQL> select seq_name.nextval from dual;
100

SQL> alter sequence seq_name
increment by 150;

SQL> select seq_name.nextval from dual;
250

It works!!

Try fetching next value once again..

SQL> select seq_name.nextval from dual;
400

Oops!! It incremented by 150.

Follow below step to increment your sequence without behaving like as above.
Now let us increment to 500.

SQL> alter sequence seq_name
increment by 100;

SQL> select seq_name.nextval from dual;
500

Reset the increment parameter!!
SQL> alter sequence seq_name
increment by 1;

SQL> select seq_name.nextval from dual;
501

SQL> select seq_name.nextval from dual;
502



****Happy CoDiNg!!****

No comments:

Post a Comment