How to create sequence in PL/SQL

In this article I describe how to create the sequence in PL/SQL.
  • 2347

Introduction

A sequence is a object in Oracle. Sequence is used to create autonumber field in oracle. The number generated are unique and can be act as primary key.

Syntax

CREATE SEQUENCE sequence_name

  MINVALUE value

  MAXVALUE value

  START WITH value

  INCREMENT BY value

  CACHE value; 

Example:

CREATE SEQUENCE sequence_emp

  MINVALUE 1

  MAXVALUE 100

  START WITH 1

  INCREMENT BY 1

  CACHE 20;

This would create a sequence object called sequence_emp. The first sequence number will be 1 and each subsequent number would increment by 1. It will cache up to 20 values for performance.If MAXVALUE is not provided then its default is set up to 999999999999999999999999999.

© 2020 DotNetHeaven. All rights reserved.