Return to Snippet

Revision: 30472
at August 14, 2010 05:09 by mprabhuram


Initial Code
--Create Sequence

CREATE SEQUENCE seq_campus_site_id;

-- use a sequence

SELECT seq_campus_site_id.NEXTVAL FROM dual;

-- Simple Autonumber With Sequence Into Two Tables

CREATE SEQUENCE seq_division_id;

INSERT INTO campus_site
(site_id, organization_name, campus_name)
VALUES
(seq_campus_site_id.NEXTVAL, 'Univ. of Washington', 'Tacoma');

INSERT INTO division
(division_id, site_id, division_name)
VALUES
(seq_division_id.NEXTVAL, seq_campus_site_id.CURRVAL, 'Engineering');

SELECT *
FROM campus_site;

SELECT *
FROM division;

-- Last Number Selected From Sequence

SELECT sequence_name, last_number
FROM user_sequences;

Initial URL
http://psoug.org/reference/sequences.html

Initial Description
Sequence is used to generate auto incrementing numbers

Initial Title
Oracle Sequence

Initial Tags
Oracle

Initial Language
SQL