Chitika Add

Wednesday, October 23

Sequences in Oracle



CREATE TABLE Samples
(
 SampID     NUMBER(4)
 Constraint SampID_PK PRIMARY  KEY,
 SampName   VARCHAR2(25),
 SampDate   DATE
 );

CREATE SEQUENCESampleSeq
INCREMENT By 1
START WITH 0
MINVALUE 0
MAXVALUE 5
NOCACHE
NOCYCLE

INSERT INTO Samples
(SampID, SampName,  SampDate)
VALUES
(SampleSeq.NEXTVAL, 'SAMPLE', '31-AUG-05');

SELECT * FROM Samples;

CREATE TABLE SampleCy
(
 SampID     NUMBER(4)
 Constraint SampIDD_PK PRIMARY  KEY,
 SampName   VARCHAR2(25),
 SampDate   DATE
 );

CREATE SEQUENCESampSeqC
INCREMENT By 1
START WITH 0
MINVALUE 0
MAXVALUE 5
NOCACHE
CYCLE

CREATE SEQUENCESampSeqD
INCREMENT BY -1
START WITH 5
MAXVALUE 5
MINVALUE 0
NOCACHE
NOCYCLE;

No comments: