Friday, 27th April 2012
Follow WikiJava on twitter now. @Wikijava

Create sequence.sql

From WikiJava

Jump to: navigation, search


This tutorial talks about how to create sequences in oracle.

Contents

the article

This is a simple tutorial on how to create a sequence in oracle sql. Sequences are used to auto increment a field's value every time a new row is inserted into a table.

sequence.sql

REM CREATE the SEQUENCE AND give it a name
CREATE SEQUENCE dept_deptid_seq
 
 
REM SET the INCREMENT VALUE IN this CASE the VALUE IS incremented BY 10 every TIME a NEW ROW IS inserted.
INCREMENT BY 10
 
 
REM SET the starting point FOR the SEQUENCE 
START WITH 310
 
 
REM SET the maximum VALUE FOR the SEQUENCE 
MAXVALUE 999
 
 
REM  setting this attribute means that a NUMBER can NOT be reassigned even WHEN a ROW IS deleted
NOCYCLE
;

using_sequence.sql

REM instead OF a USER inserting the department_id the SEQUENCE IS called AND the next VALUE IS inserted
INSERT  INTO departments (department_id,department_name,manager_id,location_id)
 
VALUES (dept_deptid_seq.NEXTVAL,'Systems',103,1000);


Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Comments on wikijava are disabled now, cause excessive spam.