Skip to content

Instantly share code, notes, and snippets.

@Baztoune
Created February 15, 2013 09:59
Show Gist options
  • Save Baztoune/4959457 to your computer and use it in GitHub Desktop.
Save Baztoune/4959457 to your computer and use it in GitHub Desktop.
-- 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