Quick Search:
 
 Oracle PL/SQL: SEQUENCE: Create sequence demo Jump to:  
Category: >> Oracle PL/SQL >> SEQUENCE: Create sequence demo  

<< lastnext >>

Snippet Name: SEQUENCE: Create sequence demo

Description: A sequence is an object in Oracle that is used to generate an autonumber field (a number sequence). This is often used to create a unique number to act as a primary key.

Also see:
» SEQUENCE: Demo code and Examples
» SEQUENCE: Find sequence MAX value
» SEQUENCE: Reset a sequence to a predef...
» SEQUENCE: get sequence value into vari...
» SEQUENCE: Autonumber into two tables

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 06th, 2009

CREATE SEQUENCE sequence_name
    MINVALUE VALUE
    MAXVALUE VALUE
    START WITH VALUE
    INCREMENT BY VALUE
    CACHE VALUE;
 
-- If you omit the MAXVALUE option, your sequence will 
-- automatically default to:
 
    MAXVALUE 99999999999999999999999999
 
 
-- create sequence demo:
 
CREATE SEQUENCE supplier_seq
     MINVALUE 1
     MAXVALUE 999999999999999999999999999
     START WITH 1
     INCREMENT BY 1
     CACHE 20;
 
Sequence created.
 
 
 SELECT supplier_seq.NEXTVAL FROM dual;
 
   NEXTVAL
----------
         1
 
 SELECT supplier_seq.NEXTVAL FROM dual;
 
   NEXTVAL
----------
         2
 
 SELECT supplier_seq.NEXTVAL FROM dual;
 
   NEXTVAL
----------
         3
 
 SELECT supplier_seq.NEXTVAL FROM dual;
 
   NEXTVAL
----------
         4
 
 
DROP sequence supplier_seq;
 
Sequence dropped.


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org