A sequence is a separate database object in Oracle.
In MySQL, when you have an auto-increment column and INSERT is a new row in the table, you just don't mention the auto-increment column, and MySQL puts it there. You can then insert the same number into another table by specifying LAST_INSERT_ID() .
INSERT INTO person (name, date) VALUES ('joe', '2015-01-01'); INSERT INTO contact (person_id, phone) VALUES (LAST_INSERT_ID(), '555-1212');
In Oracle, you can populate the id column by specifying a property of the .nextval object. You can get the value you just used for this sequence by specifying its .currval property.
INSERT INTO person (id, name, date)
Each time you specify a .nextval property of a sequence, it is guaranteed to give a new number.
Serial objects are pretty cool when you need unique numbers that are not directly related to the primary key of any table. You can do this in MySQL, but this is kludge: if you create the following table:
CREATE TABLE sequence ( sequence_id BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`sequence_id`) )
Then complete these three queries one by one:
INSERT INTO sequence () VALUES (); DELETE FROM sequence WHERE sequence_id < LAST_INSERT_ID(); SELECT LAST_INSERT_ID() AS sequence;
The third request is guaranteed to return a unique serial number. This guarantee is maintained even if you have dozens of different client programs connected to your database. (The DELETE query simply keeps this pointless table from taking up too much space.)
In Oracle, you create a sequence
create sequence seq
and then just
SELECT seq.nextval FROM DUAL
to get a new serial number and it. This also guarantees uniqueness even with dozens of connected client programs.
Similarly, if you need the value of the sequence that you just generated using .nextval , you can send this command and get it.
SELECT seq.currval FROM DUAL
As with MySQL LAST_INSERT_ID() , this session is processed by the session, so another client using the sequence will not force you to get your number instead of yours.
Bottom line: both DBMSs can generate unique integers. The integrity of both circuits is designed to be stored on servers that stops and restarts. Oracle sequence is more flexible.