How to set che CURRVAL in a sequence without dropping / recreating it.

Can you set the currval in a sequence without having to drop and recreate
the sequence?  

Can't we just use alter or update?

Please provide defailed examples.

LVL 1
hc2342uhxx3vw36x96hqAsked:
Who is Participating?
 
MarkusIdConnect With a Mentor Commented:
Question:  How do we set the LASTVALUE value in an Oracle Sequence?

Answer:  You can change the LASTVALUE for an Oracle sequence, by executing an ALTER SEQUENCE command.

For example, if the last value used by the Oracle sequence was 100 and you would like to reset the sequence to serve 225 as the next value. You would execute the following commands.

alter sequence seq_name
increment by 124;

select seq_name.nextval from dual;

alter sequence seq_name
increment by 1;

Now, the next value to be served by the sequence will be 225.

Source:http://www.techonthenet.com/oracle/sequences.php
0
 
DavidConnect With a Mentor Senior Oracle Database AdministratorCommented:
Think about it for a moment.  Say that a sequence is defined as a table's primary key.  Having the ability to manually define the current or next values would defeat its purpose to provide unique sequential values.
And of course, Mark meant 224 instead of 124 :D
 
0
 
hc2342uhxx3vw36x96hqAuthor Commented:
Many thanks to MarkusId and to dvz for the 124 => 224 bug correction :-D
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.