[Oracle] Automatic Sequential Number Generation Method

Tadashi Shigeoka ·  Tue, October 18, 2011

I looked up the automatic sequential numbering method in Oracle database, so here’s a memo.

In Oracle, unlike MySQL, it seems you can’t automatically generate unique numbers by specifying column attributes.

Instead, you use sequence objects. Creating a sequence object is as follows:

CREATE SEQUENCE ID_SEQ;

To get a unique number from a sequence, use the NEXTVAL pseudo-column:

SELECT ID_SEQ.NEXTVAL FROM DUAL;

Also, to get the current number, use the CURRVAL pseudo-column:

SELECT ID_SEQ.CURRVAL FROM DUAL;

That’s all.

【Reference】

連番の自動採番方法|Archive Redo Blog (Automatic Sequential Numbering Method | Archive Redo Blog)

スキーマ - オラクル・Oracleをマスターするための基本と仕組み (Schema - Basics and Mechanisms for Mastering Oracle)

That’s all from the Gemba.