ALTER TABLE CA_HYBRIDIZATIONFILEUPLOAD ADD (GPRSPOTFILELOCATION
VARCHAR2(200));

ALTER TABLE BIOMATERIAL ADD ( 
  COPIED NUMBER(1) DEFAULT 0 );

ALTER TABLE PROTOCOLAPPLICATION MODIFY PROTOCOL_ID NULL;

ALTER TABLE HARDWAREAPPLICATION MODIFY HARDWARE_ID NULL;

ALTER TABLE SOFTWAREAPPLICATION MODIFY SOFTWARE_ID NULL;

DECLARE
    newId NUMBER;
BEGIN
    newId := 1015897516080136;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS )	
	VALUES (newId, 'QT:SpotNum', 'SpotNum', 'org.biomage.QuantitationType.SpecializedQuantitationType'); 
	newId := newId + 1;	
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Image-x', 'Image-x', 'org.biomage.QuantitationType.SpecializedQuantitationType');
    newId := newId + 1; 
 	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Image-y', 'Image-y', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Arr-colx', 'Arr-colx', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Arr-rowy', 'Arr-rowy', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Spot-colx', 'Spot-colx', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Spot-rowy', 'Spot-rowy', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Flag', 'Flag', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:nfore', 'nfore', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:nback', 'nback', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:DapiFore', 'DapiFore', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:DapiBack', 'DapiBack', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Dapi', 'Dapi', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestFore', 'TestFore', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestForeSD', 'TestForeSD', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestBack', 'TestBack', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestBackSD', 'TestBackSD', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Test', 'Test', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefFore', 'RefFore', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefForeSD', 'RefForeSD', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefBack', 'RefBack', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefBackSD', 'RefBackSD', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Ref', 'Ref', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Log2Rat', 'Log2Rat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1; 
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RawRat', 'RawRat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:SpotCorr', 'SpotCorr', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestZstat', 'TestZstat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefZstat', 'RefZstat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:MinF-B', 'MinF-B', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Slope', 'Slope', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Log2Slope', 'Log2Slope', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:TestIntercept', 'TestIntercept', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:RefIntercept', 'RefIntercept', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:OriginDist', 'OriginDist', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:MeanLog2Rat', 'MeanLog2Rat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:MeanRat', 'MeanRat', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:MedianRatio', 'MedianRatio', 'org.biomage.QuantitationType.SpecializedQuantitationType');
	newId := newId + 1;
	INSERT INTO QUANTITATIONTYPE ( ID, IDENTIFIER, NAME, OJBCONCRETECLASS ) 
	VALUES (newId, 'QT:Log2MedRat', 'Log2MedRat', 'org.biomage.QuantitationType.SpecializedQuantitationType');     
END;
/

Insert into DATABASE
   (ID, DESC_SECURITY_ID, IDENTIFIER, NAME, VERSION, URI, SECURED_ELEMENT_ID, CATEGORY, USERDEFINED)
 Values
   (33, NULL, 'NCICB', 'NCICB Seed entries', 
    NULL, NULL, NULL, NULL, 0);

Insert into DATABASEENTRY
   (ID, TYPE_ID, DATABASE_ID, DESCRIPTION_ID, BIOSEQUENCE_ID, ACCESSION, ACCESSIONVERSION, URI, SECURED_ELEMENT_ID,
        BIBLIOGRAPHIC_REFERENCE_ID)
 Values
   (101440, NULL, 33, NULL, 
    NULL, NULL, NULL, NULL, NULL, 
    NULL);

Insert into ONTOLOGYENTRY
   (ID, SECURED_ELEMENT_ID, CATEGORY, VALUE, CONTACT_ID, ONTOLOGY_REFERENCE_ID, EXPERIMENTAL_FACTOR_ID, COMPOUND_ID, DESCRIPTION, OJBCONCRETECLASS, AGE_VALUE_ID, MEASUREMENT_ID, MIN_VALUE_ID, MIN_MEASUREMENT_ID, MAX_VALUE_ID, MAX_MEASUREMENT_ID, INITIAL_TIME_POINT_ID, WEIGHT_ID, WEIGHT_MEASUREMENT_ID, HEIGHT_ID, HEIGHT_MEASUREMENT_ID, BIBLIOGRAPHIC_REFERENCE_ID)
 Values
   (101441, NULL, 'OrientationMarkPosition', 'top', 
    NULL, 101440, NULL, NULL, NULL, 
    'org.biomage.Description.OntologyEntry', NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL);

Insert into ONTOLOGYENTRY
   (ID, SECURED_ELEMENT_ID, CATEGORY, VALUE, CONTACT_ID, ONTOLOGY_REFERENCE_ID, EXPERIMENTAL_FACTOR_ID, COMPOUND_ID, DESCRIPTION, OJBCONCRETECLASS, AGE_VALUE_ID, MEASUREMENT_ID, MIN_VALUE_ID, MIN_MEASUREMENT_ID, MAX_VALUE_ID, MAX_MEASUREMENT_ID, INITIAL_TIME_POINT_ID, WEIGHT_ID, WEIGHT_MEASUREMENT_ID, HEIGHT_ID, HEIGHT_MEASUREMENT_ID, BIBLIOGRAPHIC_REFERENCE_ID)
 Values
   (101442, NULL, 'OrientationMarkPosition', 'bottom', 
    NULL, 101440, NULL, NULL, NULL, 
    'org.biomage.Description.OntologyEntry', NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL);

Insert into ONTOLOGYENTRY
   (ID, SECURED_ELEMENT_ID, CATEGORY, VALUE, CONTACT_ID, ONTOLOGY_REFERENCE_ID, EXPERIMENTAL_FACTOR_ID, COMPOUND_ID, DESCRIPTION, OJBCONCRETECLASS, AGE_VALUE_ID, MEASUREMENT_ID, MIN_VALUE_ID, MIN_MEASUREMENT_ID, MAX_VALUE_ID, MAX_MEASUREMENT_ID, INITIAL_TIME_POINT_ID, WEIGHT_ID, WEIGHT_MEASUREMENT_ID, HEIGHT_ID, HEIGHT_MEASUREMENT_ID, BIBLIOGRAPHIC_REFERENCE_ID)
 Values
   (101443, NULL, 'OrientationMarkPosition', 'left', 
    NULL, 101440, NULL, NULL, NULL, 
    'org.biomage.Description.OntologyEntry', NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL);

Insert into ONTOLOGYENTRY
   (ID, SECURED_ELEMENT_ID, CATEGORY, VALUE, CONTACT_ID, ONTOLOGY_REFERENCE_ID, EXPERIMENTAL_FACTOR_ID, COMPOUND_ID, DESCRIPTION, OJBCONCRETECLASS, AGE_VALUE_ID, MEASUREMENT_ID, MIN_VALUE_ID, MIN_MEASUREMENT_ID, MAX_VALUE_ID, MAX_MEASUREMENT_ID, INITIAL_TIME_POINT_ID, WEIGHT_ID, WEIGHT_MEASUREMENT_ID, HEIGHT_ID, HEIGHT_MEASUREMENT_ID, BIBLIOGRAPHIC_REFERENCE_ID)
 Values
   (101444, NULL, 'OrientationMarkPosition', 'right', 
    NULL, 101440, NULL, NULL, NULL, 
    'org.biomage.Description.OntologyEntry', NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL, NULL, NULL, 
    NULL, NULL, NULL);

DROP SEQUENCE SEQ_Extendable;

DROP SEQUENCE SEQ_CA_HYBRIDIZATIONFILEUPLOAD;

DROP SEQUENCE SEQ_CA_ADDITIONALFILE;

DROP SEQUENCE SEQ_NAMEVALUETYPE;

DROP SEQUENCE SEQ_MOM_MESSAGEDATA;

DECLARE
  grabsize NUMBER;
  currentMaxKey NUMBER;
  c1 BINARY_INTEGER;
  myException EXCEPTION;
BEGIN
  grabsize := 1000;	
  SELECT MAX(NVL(ID, 1)) INTO currentMaxKey FROM
  (SELECT MAX(ID) AS ID FROM AFFYBACKGROUND
  UNION
  SELECT MAX(ID) AS ID FROM AFFYCALLSUMMARY
  UNION
  SELECT MAX(ID) AS ID FROM AFFYCONTROL
  UNION
  SELECT MAX(ID) AS ID FROM AFFYHOUSEKEEPINGCONTROL
  UNION
  SELECT MAX(ID) AS ID FROM AFFYMETRIX
  UNION
  SELECT MAX(ID) AS ID FROM AFFYSPIKECONTROL
  UNION
  SELECT MAX(ID) AS ID FROM AGILENT
  UNION
  SELECT MAX(ID) AS ID FROM ARRAY
  UNION
  SELECT MAX(ID) AS ID FROM ARRAYDESIGN
  UNION
  SELECT MAX(ID) AS ID FROM ARRAYGROUP
  UNION
  SELECT MAX(ID) AS ID FROM ARRAYMANUFACTURE
  UNION
  SELECT MAX(ID) AS ID FROM ARRAYMANUFACTUREDEVIATION
  UNION
  SELECT MAX(ID) AS ID FROM AUDIT_TBL
  UNION
  SELECT MAX(ID) AS ID FROM BIBLIOGRAPHICREFERENCE
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAY
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYCREATION
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYDATA
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYDATACLUSTER
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYDIMENSION
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYMAP
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYMAPPING
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYTREATMENT
  UNION
  SELECT MAX(ID) AS ID FROM BIOASSAYTUPLE
  UNION
  SELECT MAX(ID) AS ID FROM BIODATAVALUES
  UNION
  SELECT MAX(ID) AS ID FROM BIOMATERIAL
  UNION
  SELECT MAX(ID) AS ID FROM BIOMATERIALMEASUREMENT
  UNION
  SELECT MAX(ID) AS ID FROM BIOSEQUENCE
  UNION
  SELECT MAX(ID) AS ID FROM CHANNEL
  UNION
  SELECT MAX(ID) AS ID FROM COMPOSITESEQUENCE
  UNION
  SELECT MAX(ID) AS ID FROM COMPOUND
  UNION
  SELECT MAX(ID) AS ID FROM COMPOUNDMEASUREMENT
  UNION
  SELECT MAX(ID) AS ID FROM CONTACT
  UNION
  SELECT MAX(ID) AS ID FROM DATABASE
  UNION
  SELECT MAX(ID) AS ID FROM DATABASEENTRY
  UNION
  SELECT MAX(ID) AS ID FROM DATAEXTERNAL
  UNION
  SELECT MAX(ID) AS ID FROM DATAINTERNAL
  UNION
  SELECT MAX(ID) AS ID FROM DATUM
  UNION
  SELECT MAX(ID) AS ID FROM DESCRIPTION
  UNION
  SELECT MAX(ID) AS ID FROM DESIGNELEMENTDIMENSION
  UNION
  SELECT MAX(ID) AS ID FROM DESIGNELEMENTGROUP
  UNION
  SELECT MAX(ID) AS ID FROM DESIGNELEMENTMAP
  UNION
  SELECT MAX(ID) AS ID FROM DESIGNELEMENTMAPPING
  UNION
  SELECT MAX(ID) AS ID FROM DESIGNELEMENTTUPLE
  UNION
  SELECT MAX(ID) AS ID FROM EXPERIMENT
  UNION
  SELECT MAX(ID) AS ID FROM EXPERIMENTALFACTOR
  UNION
  SELECT MAX(ID) AS ID FROM EXPERIMENTDESIGN
  UNION
  SELECT MAX(ID) AS ID FROM EXTERNALREFERENCE
  UNION
  SELECT MAX(ID) AS ID FROM FACTORVALUE
  UNION
  SELECT MAX(ID) AS ID FROM FEATURE
  UNION
  SELECT MAX(ID) AS ID FROM FEATUREDEFECT
  UNION
  SELECT MAX(ID) AS ID FROM FEATUREEXTRACTION
  UNION
  SELECT MAX(ID) AS ID FROM FEATUREINFORMATION
  UNION
  SELECT MAX(ID) AS ID FROM FEATURELOCATION
  UNION
  SELECT MAX(ID) AS ID FROM FIDUCIAL
  UNION
  SELECT MAX(ID) AS ID FROM HARDWARE
  UNION
  SELECT MAX(ID) AS ID FROM HARDWAREAPPLICATION
  UNION
  SELECT MAX(ID) AS ID FROM IMAGE
  UNION
  SELECT MAX(ID) AS ID FROM MANUFACTURELIMS
  UNION
  SELECT MAX(ID) AS ID FROM MEASUREMENT
  UNION
  SELECT MAX(ID) AS ID FROM MISMATCHINFORMATION
  UNION
  SELECT MAX(ID) AS ID FROM NAMEVALUETYPE
  UNION
  SELECT MAX(ID) AS ID FROM NODE
  UNION
  SELECT MAX(ID) AS ID FROM NODECONTENTS
  UNION
  SELECT MAX(ID) AS ID FROM NODEVALUE
  UNION
  SELECT MAX(ID) AS ID FROM ONTOLOGYENTRY
  UNION
  SELECT MAX(ID) AS ID FROM ORGANIZATION
  UNION
  SELECT MAX(ID) AS ID FROM PARAMETER
  UNION
  SELECT MAX(ID) AS ID FROM PARAMETERIZABLE
  UNION
  SELECT MAX(ID) AS ID FROM PARAMETERIZABLEAPPLICATION
  UNION
  SELECT MAX(ID) AS ID FROM PARAMETERVALUE
  UNION
  SELECT MAX(ID) AS ID FROM PERSON
  UNION
  SELECT MAX(ID) AS ID FROM POSITION
  UNION
  SELECT MAX(ID) AS ID FROM POSITIONDELTA
  UNION
  SELECT MAX(ID) AS ID FROM PROTOCOL
  UNION
  SELECT MAX(ID) AS ID FROM PROTOCOLAPPLICATION
  UNION
  SELECT MAX(ID) AS ID FROM QUANTITATIONTYPE
  UNION
  SELECT MAX(ID) AS ID FROM QUANTITATIONTYPEDIMENSION
  UNION
  SELECT MAX(ID) AS ID FROM QUANTITATIONTYPEMAP
  UNION
  SELECT MAX(ID) AS ID FROM QUANTITATIONTYPEMAPPING
  UNION
  SELECT MAX(ID) AS ID FROM QUANTITATIONTYPETUPLE
  UNION
  SELECT MAX(ID) AS ID FROM REPORTER
  UNION
  SELECT MAX(ID) AS ID FROM SECURITY
  UNION
  SELECT MAX(ID) AS ID FROM SECURITYGROUP
  UNION
  SELECT MAX(ID) AS ID FROM SEQFEATURE
  UNION
  SELECT MAX(ID) AS ID FROM SEQFEATURELOCATION
  UNION
  SELECT MAX(ID) AS ID FROM SEQUENCEPOSITION
  UNION
  SELECT MAX(ID) AS ID FROM SOFTWARE
  UNION
  SELECT MAX(ID) AS ID FROM SOFTWAREAPPLICATION
  UNION
  SELECT MAX(ID) AS ID FROM TRANSFORMATION
  UNION
  SELECT MAX(ID) AS ID FROM TREATMENT
  UNION
  SELECT MAX(ID) AS ID FROM UNIT
  UNION
  SELECT MAX(ID) AS ID FROM ZONE
  UNION
  SELECT MAX(ID) AS ID FROM ZONEDEFECT
  UNION
  SELECT MAX(ID) AS ID FROM ZONEGROUP
  UNION
  SELECT MAX(ID) AS ID FROM ZONELAYOUT);

  c1 := dbms_sql.open_cursor;
  dbms_sql.parse(c1, 'CREATE SEQUENCE SEQ_Extendable INCREMENT BY 1 START WITH ' || CEIL((NVL(currentMaxKey, 0) + 1) / grabsize) || ' MINVALUE 1 NOCYCLE', dbms_sql.native);
  dbms_sql.close_cursor(c1);      
  SELECT MAX(ID) INTO currentMaxKey FROM CA_HYBRIDIZATIONFILEUPLOAD;

  c1 := dbms_sql.open_cursor;
  dbms_sql.parse(c1, 'CREATE SEQUENCE SEQ_CA_HYBRIDIZATIONFILEUPLOAD INCREMENT BY 1 START WITH ' || CEIL((NVL(currentMaxKey, 0) + 1) / grabsize) || ' MINVALUE 1 NOCYCLE', dbms_sql.native);
  dbms_sql.close_cursor(c1);
  SELECT MAX(ID) INTO currentMaxKey FROM CA_ADDITIONALFILE;

  c1 := dbms_sql.open_cursor;
  dbms_sql.parse(c1, 'CREATE SEQUENCE SEQ_CA_ADDITIONALFILE INCREMENT BY 1 START WITH ' || CEIL((NVL(currentMaxKey, 0) + 1) / grabsize) || ' MINVALUE 1 NOCYCLE', dbms_sql.native);
  dbms_sql.close_cursor(c1);    
  SELECT MAX(ID) INTO currentMaxKey FROM NAMEVALUETYPE;

  c1 := dbms_sql.open_cursor;
  dbms_sql.parse(c1, 'CREATE SEQUENCE SEQ_NAMEVALUETYPE INCREMENT BY 1 START WITH ' || CEIL((NVL(currentMaxKey, 0) + 1) / grabsize) || ' MINVALUE 1 NOCYCLE', dbms_sql.native);
  dbms_sql.close_cursor(c1);      
  SELECT MAX(ID) INTO currentMaxKey FROM MOM_MESSAGEDATA;

  c1 := dbms_sql.open_cursor;
  dbms_sql.parse(c1, 'CREATE SEQUENCE SEQ_MOM_MESSAGEDATA INCREMENT BY 1 START WITH ' || CEIL((NVL(currentMaxKey, 0) + 1) / grabsize) || ' MINVALUE 1 NOCYCLE', dbms_sql.native);
  dbms_sql.close_cursor(c1);
END;
/



DECLARE
  newId NUMBER;
        category VARCHAR2(50);
        dbId NUMBER;
        dbEntryId NUMBER;
BEGIN
  SELECT ID INTO dbId FROM DATABASE WHERE IDENTIFIER = 'MO';
  category := 'ConcentrationUnit';
        SELECT MAX_KEY INTO dbEntryId FROM OJB_HL_SEQ WHERE TABLENAME =
'SEQ_Extendable';
        UPDATE OJB_HL_SEQ SET MAX_KEY = MAX_KEY + 1 WHERE TABLENAME =
'SEQ_Extendable';
        INSERT INTO DATABASEENTRY (ID, DATABASE_ID)
        VALUES(dbEntryId, dbId);
        SELECT MAX_KEY INTO newId FROM OJB_HL_SEQ WHERE TABLENAME =
'SEQ_Extendable';
        UPDATE OJB_HL_SEQ SET MAX_KEY = MAX_KEY + 1 WHERE TABLENAME =
'SEQ_Extendable';
        INSERT INTO ONTOLOGYENTRY (ID, CATEGORY, VALUE,
ONTOLOGY_REFERENCE_ID)
        VALUES(newId, category, 'nM', dbEntryId);
END;
/


