Sequences

  • sequence is a schema object that can generate unique sequential values.
  • These values are often used for primary and unique keys.
  • You can refer to sequence values in SQL statements with these pseudocolumns:
  • CURRVAL: Returns the current value of a sequence
  • NEXTVAL: Increments the sequence and returns the next value

CREATE SEQUENCE

  • a database object from which multiple users may generate unique integers.
  • You can use sequences to automatically generate primary key values.

Syntax

Description of create_sequence.eps follows

— Let us create a sequence

View a Sequence

SELECT *
FROM SYS.SEQ$;

eXAMPLE 2

Finding the next value of a sequence: Example

Inserting sequence values into a table: Example

This example increments the employee sequence and uses its value for a new employee inserted into the sample table hr.employees:

https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Sequence-Pseudocolumns.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top