Oracle Sequences

  • Sequences are database objects.
  • Sequence is used to generate automatic numbers.
  • Sequences are used to generate primary key values automatically.
  • Sequence is an independent database object. Once sequence is created, any number of users can access the sequence simultaneously.
  • Sequence is not related to any table.

Sequence has two pseudo columns:
CURRVAL: Gives the current generated value of sequence
Syntax: Seq_name.currval;

NEXTVAL: Give the next generated value of sequence.
Syntax: Seq_name.nextval;

Sequence Syntax:

CREATE sequence seq_name
increment by no_val
starts with no_value
minvalue n
maxvalue n
cycle/nocycle
Cache/Nocache;

Example:

CREATE SEQUENCE ORA1
starts with 5
increment by 2
maxvalue 100;

sql> SELECT ORA1.nextval from dual;

Powered by k2schools