Wednesday, June 29, 2011
Advance Sequence Nextvals to sync with table
Here's a way to advance a sequence using an anonymous PL/SQL block:
DECLARE
mn integer;
mx integer;
BEGIN
SELECT MYPROJ.personnelid_seq.CURRVAL INTO mn FROM DUAL;
SELECT max(personnelid) INTO mx FROM MYPROJ.personnel;
WHILE mn <= mx LOOP
SELECT MYPROJ.personnelid_seq.NEXTVAL INTO mn FROM DUAL;
END LOOP;
SELECT igems.accountid_seq.CURRVAL INTO mn FROM DUAL;
SELECT max(accountid) INTO mx FROM MYPROJ.account;
WHILE mn <= mx LOOP
SELECT MYPROJ.accountid_seq.NEXTVAL INTO mn FROM DUAL;
END LOOP;
END;
/
COMMIT;
/
--uncomment to view current values
--SELECT MYPROJ.personnelid_seq.CURRVAL FROM DUAL;
--SELECT MYPROJ.accountid_seq.CURRVAL FROM DUAL;
Another method is to temporarily alter the sequence to advance, then set it back:
ALTER SEQUENCE seq_name INCREMENT BY 124;
SELECT seq_name.nextval FROM dual;
ALTER SEQUENCE seq_name INCREMENT BY 1;
/
Labels:
oracle
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment