betweenGo

Sequences on Oracle

by 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

Related posts:

  1. Oracle Triggers
  2. Inserting a text value with special characters
  3. SQL Insert in One Table Based on Values in Another Table
  4. Calling Oracle Stored Procedures and Functions
  5. Determining Permissions for a User


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!