Search This Blog

Friday, March 21, 2014

Oracle Sequence Example

OracleSequence

Sequences are database objects from which multiple users can generate unique integers. The sequence generator generates sequential numbers, which can help to generate unique primary keys automatically, and to coordinate keys across multiple rows or tables.


Example:

CREATE SEQUENCE order_sequence
      INCREMENT BY 1
      START WITH 1
      NOMAXVALUE
      NOCYCLE
      CACHE 10;

INSERT INTO orders (order_no)
VALUES (order_sequence.NEXTVAL);