To fix this problem you can try to find where your sequences are used and get the MAX(value) to find the next value. Alternatively you can just add a large random number, say 1,000,000, to all your sequences. For most users this will fix the problem and is very easy to do. Here's how:
-- Update all sequences
DECLARE
v_increase_by NUMBER;
v_bkp_increment_by NUMBER;
v_str VARCHAR2 (1000);
v_count NUMBER;
BEGIN
v_increase_by := 1000000;
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;
/
I got this
ReplyDelete"Invalid start of code"
what did I do wrong again =)
You have to use it in a function or open it in a test window not sql window.
Deletethanks very much, worked a treat and saved me a lot of bother
ReplyDelete