0

Ok, So in learning about migrating from MySQL 8 to Oracle 19 I have run into an issue. My tables in MySQL have auto_increment on the primary key. When I walk through the migration and get my master.sql script that has all of my metadata for object creation. I have noticed that the DDL for the tables has the identity column starting at 0 and not the auto_increment number from MySQL. This runs into an issue when inserting data if the number of rows in the table in Oracle is less than the identity column base value. I used Goldengate to insert the data and the sequence that is system generated for the identity column only gets bumped up for each insert of data. How can I get the correct value when using SQL Developer to do a migration? I have a work around in PL/SQL but would like to get the correct value form the migration process. Thanks

CREATE TABLE my_table (
 id NUMBER(10,0) GENERATED BY DEFAULT ON NULL AS IDENTITY START WITH 0 INCREMENT BY 1 MINVALUE 0 NOMAXVALUE ,
 created DATE NOT NULL,
 modified DATE NOT NULL,
 user_id NUMBER(10,0) NOT NULL
);

should be

CREATE TABLE my_table (
 id NUMBER(10,0) GENERATED BY DEFAULT ON NULL AS IDENTITY START WITH 100 INCREMENT BY 1 MINVALUE 0 NOMAXVALUE ,
 created DATE NOT NULL,
 modified DATE NOT NULL,
 user_id NUMBER(10,0) NOT NULL
);
asked May 2, 2024 at 16:04
4
  • The starting value generally shouldn't matter. All that matters for columns like this is that they're unique. Commented May 2, 2024 at 16:10
  • It's not clear what kind of answer you expect here. If you consider this wrong, you should submit a bug report about the migration tool. Commented May 2, 2024 at 16:11
  • it does eaxcly what you wanted dbfiddle.uk/s57SKrXX and starts with 100 Commented May 2, 2024 at 17:22
  • I will put in a bug since if you see my comments below there will be an issue. Commented May 2, 2024 at 22:10

1 Answer 1

0

A better option might be to add an additional step.

Step 1: Create the table

CREATE TABLE my_table (
 id NUMBER(10,0) GENERATED BY DEFAULT ON NULL AS IDENTITY START WITH 0 INCREMENT BY 1 MINVALUE 0 NOMAXVALUE ,
 created DATE NOT NULL,
 modified DATE NOT NULL,
 user_id NUMBER(10,0) NOT NULL
);

Step 2: insert the migrated data with primary key values.

INSERT INTO my_table VALUEs (100,SYSDATE, SYSDATE,1);
INSERT INTO my_table VALUEs (101,SYSDATE, SYSDATE,2);
INSERT INTO my_table VALUEs (110,SYSDATE, SYSDATE,3);

Step 3: reset the identity column based on current highest value.

ALTER TABLE my_table MODIFY ID GENERATED BY DEFAULT ON NULL AS IDENTITY (START WITH LIMIT VALUE);

The next row will now generate id value 111. Doing it this way you don't need to bother calculating the initial value.

tinlyx
3,84014 gold badges50 silver badges79 bronze badges
answered May 2, 2024 at 18:42
5
  • no need for that see my comment Commented May 2, 2024 at 19:24
  • In that case I don't understand what your actual question is... Commented May 2, 2024 at 19:44
  • 1
    @Koen Lostrie that is what I had to do an alter table after the fact. I don't understand why SQL Developer doesn't pull the auto_increment value when it generates the DDL for the table. You can see that DDL when you use MySQL workbench and pull the MySQL DDL. Commented May 2, 2024 at 22:08
  • You see this becomes in an issue if the number of rows is less than the auto_increment value in MYSQL. Then the inserts that happen in Goldengate only go up to the number of rows and then identity sequence is then behind the max number for the column. Commented May 2, 2024 at 22:10
  • A table with an identity column is a table with an index behind the scenes. The DDL for a table and sequence is generated from the data dictionary, I assume dbms_metadata.get_ddl. The data dictionary does not store the last value of the sequence - that part is up to you. Commented May 3, 2024 at 6:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.