Created
February 18, 2011 14:30
-
-
Save alf239/833716 to your computer and use it in GitHub Desktop.
Fix the Oracle sequences
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
select * from all_sequences where sequence_owner = sys_context('USERENV', 'SESSION_USER') |
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
CREATE OR REPLACE PROCEDURE fix_sequence(tbl VARCHAR, field VARCHAR, seq VARCHAR) | |
IS | |
current_id NUMBER; | |
current_seq NUMBER; | |
BEGIN | |
EXECUTE immediate 'select max(' || field || ') from ' || tbl into current_id; | |
EXECUTE immediate 'select ' || seq || '.nextval from dual' into current_seq; | |
IF (current_id > current_seq) THEN | |
EXECUTE immediate 'alter sequence ' || seq || ' increment by ' || to_char(current_id - current_seq); | |
EXECUTE immediate 'select ' || seq || '.nextval from dual' into current_seq; | |
EXECUTE immediate 'alter sequence ' || seq || ' increment by 1'; | |
END IF; | |
END; | |
/ | |
CALL fix_sequence('A2_DESIGNELEMENT', 'DESIGNELEMENTID', 'A2_DESIGNELEMENT_SEQ'); | |
CALL fix_sequence('A2_GENEGPV', 'GENEGPVID', 'A2_GENEGPV_SEQ'); | |
CALL fix_sequence('A2_GENEPROPERTYVALUE', 'GENEPROPERTYVALUEID', 'A2_GENEPROPERTYVALUE_SEQ'); | |
CALL fix_sequence('A2_GENEPROPERTY', 'GENEPROPERTYID', 'A2_GENEPROPERTY_SEQ'); | |
CALL fix_sequence('A2_GENE', 'GENEID', 'A2_GENE_SEQ'); | |
CALL fix_sequence('A2_ONTOLOGYTERM', 'ONTOLOGYTERMID', 'A2_ONTOLOGYTERM_SEQ'); | |
CALL fix_sequence('A2_ORGANISM', 'ORGANISMID', 'A2_ORGANISM_SEQ'); | |
CALL fix_sequence('A2_PROPERTYVALUE', 'PROPERTYVALUEID', 'A2_PROPERTYVALUE_SEQ'); | |
CALL fix_sequence('A2_PROPERTY', 'PROPERTYID', 'A2_PROPERTY_SEQ'); | |
CALL fix_sequence('A2_SAMPLEPV', 'SAMPLEPVID', 'A2_SAMPLEPV_SEQ'); | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment