Resetting a sequence

Last update on July 2, 2009 07:09 AM by jak58
Published by jak58

Resetting a sequence







To reset a sequence SEQ created through the command:
CREATE SEQUENCE seq; 


Search for its current value via the command:
SEQ.CURRVAL SELECT FROM DUAL; 


Then change the sequence by adding the option by adding increment value VAL(current value - 1) to reset the sequence to 1:
ALTER SEQUENCE SEQ INCREMENT by -VAL; 


Then run the command that will reset the sequence:
SEQ.NEXTVAL SELECT FROM DUAL; 


To restore the increment of the sequence:
ALTER SEQUENCE SEQ INCREMENT by 1; 



Example:

SQL> create sequence seq; 

Sequence created. 

SQL> select seq.nextval from dual; 

   NEXTVAL
----------
         1

SQL> select seq.nextval from dual;

   NEXTVAL
----------
         2

SQL> select seq.nextval from dual;

   NEXTVAL
----------
         3

SQL> select seq.currval from dual; 

    CURRVAL 
---------- 
          3 
SQL> alter sequence seq increment by -2;  // 2=SEQ.CURRVAL-1

Sequence altered. 

SQL> select seq.nextval from dual; 

    NEXTVAL
---------- 
          1 

SQL> alter sequence seq increment by 1; 

Sequence altered.
Best answers for « Resetting a sequence » in :
Modifying boot sequence Show Changing Boot Device Introduction Choosing the boot sequence: Hard disk: CD/DVD Floppy drive Network Conclusion Introduction When starting from a new system or in the case that your system is failing and that you need do startup...
Lost password - Resetting the BIOS Show Lost password - Resetting the BIOS Hardware reset Software reset In the case you have forgotten or lost the password for the BIOS, (prompted when starting your computer), this tip below will help you to tackle this problem. The...
Ubuntu – Monitor your Boot Sequence with Bootchart Show Ubuntu – Monitor your Boot Sequence with Bootchart About Bootchart Installation Disabling and Enabling Bootchart About Bootchart Bootchart is a tool used to analyse your system performance in linux boot process. It process all the...
Resetting Samsung i900 Omnia ShowResetting Samsung i900 Omnia Issue Solutions Issue Your Samsung Omnia i900 Omnia phone’s processing is getting slower, tried installing incompatible application which caused some errors, the phone is resetting automatically. You...
Replacing the battery of your motherboard (CMOS battery) ShowReplacing the battery of your motherboard (CMOS battery) Topics Symptoms Replacement sequence Saving the BIOS data Identify the CMOS battery Removing the discharged battery Installing the new battery Verify the BIOS data and resetting...
How to reset your Nokia? ShowHow to reset your Nokia? Soft Reset Hard Reset Note Your Nokia phone isn't working properly or not responding quickly.Below are tips on how to reset your Nokia Mobile phones: Soft Reset Soft Reset will clear pending errors and...
Download Ulead GIF Animator ShowFor your Web site or your PowerPoint presentations, you need animated GIFs to cheer up your pages. Ulead GIF Animator is the most successful and accessible program in term of creation of animated GIF. It allows to create a simple animation sequence....
File sharing in Windows XP ShowAdvantages File sharing involves making the content of one or more directories available through the network. All Windows systems have standard devices making it easy to share the content of a directory. However, file sharing may lead to security...
BIOS optimisation ShowWhat is the BIOS? The BIOS (Basic Input/Output System) is a small memory chip located on the motherboard containing data that define the system parameters. As some BIOS data are written in a ROM, it is not possible to change them, however, certain...
Error checking ShowError checking Binary encoding is very practical for use in electronic devices such as computers, in which information can be encoded based on whether an electrical signal is present or not. However, this electrical signal may suffer disturbances...