HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Oracle sequences to MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
oraclesequencesmysql

Problem

Migrating from Oracle to MySQL we've found some many incompatibility issues. We've some workarounds for many of them, however we still have one: The Sequences

We have this table

```
CREATE TABLE "HEADS"(
"HEAD_ID" NUMBER NOT NULL ENABLE,
"COLUMN" NUMBER NOT NULL ENABLE,
"ROW" NUMBER NOT NULL ENABLE,
"VALUE" VARCHAR2(200),
"CREATED_BY" VARCHAR2(40),
"CREATED_DATE" DATE,
"MODIFIED_BY" VARCHAR2(40),
"MODIFIED_DATE" DATE

Solution

You could write your own user-defined function to generate sequence numbers. Alternatively, you could create a separate table with a single AUTO_INCREMENT column to generate new IDs: in your stored procedure you would insert a row into that table, use LAST_INSERT_ID() to fetch the generated value, then delete the inserted row.

Context

StackExchange Database Administrators Q#110854, answer score: 3

Revisions (0)

No revisions yet.