betweenGo

Sequences on Oracle

by Frank Kim on Sep.29, 2005, under Oracle

Here is an example of how to create a sequence which you can use for creating sequential numbers, typically for ID’s.

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

This is how you would then use the sequence.

INSERT INTO persons (id, name) VALUES (person_seq.NEXTVAL, 'Dylan')
INSERT INTO persons (id, name) VALUES (person_seq.NEXTVAL, 'Isaac')

If you want to select the next ID you would do it like this.

SELECT person_seq.NEXTVAL FROM Dual

To learn more, Managing Sequences and the Oracle DUAL table.

  • Share/Bookmark

Related posts:

  1. Oracle Triggers
  2. SQL Insert in One Table Based on Values in Another Table
  3. Calling Oracle Stored Procedures and Functions
  4. Inserting a text value with special characters
  5. How to Import and Create Users in Oracle


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!