User Id :    Password :      New Member   Forgot Password  
Topic: Why to use SQL Sequence and its drawbacks
Sachin Jain
29 Oct 2010 at 11:06 PM
Why to use SQL Sequence and its drawbacks .

Re: Why to use SQL Sequence and its drawbacks
Gaurav
01 Nov 2010 at 12:26 AM

In SQL Sequences are used for creating sequence numbers without any overhead of locking but one drawback is that when any of transaction is rolled back the sequence number is lost.
Generating a sequence number isn't that hard. All what you need to type is the following:
CREATE sequence my_seq start WITH 1;
Select from dual to increment your sequence number by one.
SELECT my_seq.NEXTVAL FROM dual;
What if you want to create a sequence that increments by 3?
SQL> CREATE sequence seq_3 start WITH 1 increment BY 3;
Sequence created.
SQL> SELECT seq_3.NEXTVAL FROM dual;
NEXTVAL
1
SQL> SELECT seq_3.NEXTVAL FROM dual;
NEXTVAL
4

Total Replies: 1
 
Featured Text Ad

Featured Ad