Database Reference
In-Depth Information
you one. How the sequence generates numbers, it all depends on
the way you create them.
Example:
CREATE SEQUENCE emp_seq
START WITH 1000
MAXVALUE 99999
INCREMENT BY 1
NOCYCLE;
This statement will create sequence emp_seq which will start
with 1000 and increment by 1 i.e. each time you ask for new
value from this sequence it will give you a number 1 higher than
the previous one. Maximum value would be 99999 and if you
want you can use NOMAXVALUE. CYCLE clause we use if
you want to force the sequence to start all over again once it hits
the maximum value otherwise use NOCYCLE.
Example:
SELECT emp_seq.NEXTVAL
FROM dual;
We use NEXTVAL method to retrieve the next value from the
sequence so that we don't have to worry about what id to allot to
a newly hired employee.
INSERT INTO emp_info (id, name, email)
VALUES (emp_seq.NEXTVAL, 'Gregory',
'gregory@oracle.com'
);
Example:
SELECT emp_seq.CURRVAL
FROM dual;
You can also find out the current value of the sequence using
CURRVAL method.
Search WWH ::




Custom Search