Wednesday, October 23, 2013

Sequences in Oracle



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

CREATE SEQUENCE SampleSeq
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 SEQUENCE SampSeqC
INCREMENT By 1
START WITH 0
MINVALUE 0
MAXVALUE 5
NOCACHE
CYCLE

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

1 comment:

Nasreen Basu said...

very useful really good information thanks for posting such a good information it will hepls the people a lot keep it up , Regards, obiee training in hyderabad

Post a Comment

Best Blogger TipsGet Flower Effect