Created
February 15, 2013 09:59
-
-
Save Baztoune/4959457 to your computer and use it in GitHub Desktop.
@see http://www.talkapex.com/2009/07/oracle-how-to-update-all-sequences.html
Increment all sequences by a fixed number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- src > http://www.talkapex.com/2009/07/oracle-how-to-update-all-sequences.html | |
-- Increment all sequences by a fixed number | |
DECLARE | |
v_increase_by NUMBER; | |
v_bkp_increment_by NUMBER; | |
v_str VARCHAR2 (1000); | |
v_count NUMBER; | |
BEGIN | |
v_increase_by := 2000; | |
FOR rec IN (SELECT * FROM user_sequences) LOOP | |
-- Backup current incrementation number | |
v_bkp_increment_by := rec.increment_by; | |
-- Alter the sequence to increase by a defined amount | |
v_str := 'alter sequence ' || rec.sequence_name || ' increment by ' || v_increase_by; | |
EXECUTE IMMEDIATE v_str; | |
-- Increase by that amount | |
v_str := 'select ' || rec.sequence_name || '.nextval from dual'; | |
EXECUTE IMMEDIATE v_str | |
INTO v_count; | |
-- Reset the increment factor | |
v_str := 'alter sequence ' || rec.sequence_name || ' increment by ' || v_bkp_increment_by; | |
EXECUTE IMMEDIATE v_str; | |
END LOOP; | |
END; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment