Oracle Sequence


/ Published in: SQL
Save to your folder(s)

Sequence is used to generate auto incrementing numbers


Copy this code and paste it in your HTML
  1. --Create Sequence
  2.  
  3. CREATE SEQUENCE seq_campus_site_id;
  4.  
  5. -- use a sequence
  6.  
  7. SELECT seq_campus_site_id.NEXTVAL FROM dual;
  8.  
  9. -- Simple Autonumber With Sequence Into Two Tables
  10.  
  11. CREATE SEQUENCE seq_division_id;
  12.  
  13. INSERT INTO campus_site
  14. (site_id, organization_name, campus_name)
  15. VALUES
  16. (seq_campus_site_id.NEXTVAL, 'Univ. of Washington', 'Tacoma');
  17.  
  18. INSERT INTO division
  19. (division_id, site_id, division_name)
  20. VALUES
  21. (seq_division_id.NEXTVAL, seq_campus_site_id.CURRVAL, 'Engineering');
  22.  
  23. SELECT *
  24. FROM campus_site;
  25.  
  26. SELECT *
  27. FROM division;
  28.  
  29. -- Last Number Selected From Sequence
  30.  
  31. SELECT sequence_name, last_number
  32. FROM user_sequences;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.