/ Published in: SQL
Sequence is used to generate auto incrementing numbers
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
--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;
URL: http://psoug.org/reference/sequences.html