alter sequence [message #216945] |
Wed, 31 January 2007 00:28 |
chinmay_uce02
Messages: 11 Registered: January 2007
|
Junior Member |
|
|
hi all
is it possible to decrement the current value of an oracle sequence?
thanks in advance
chinmay
|
|
|
|
Re: alter sequence [message #216960 is a reply to message #216947] |
Wed, 31 January 2007 01:29 |
chinmay_uce02
Messages: 11 Registered: January 2007
|
Junior Member |
|
|
hi Taj,
thanks for ur reply. but my query is like can we change the current value pointed by the sequence. as in ur examlpe after inserting 50 records in the table the sequence.currval points to 50. can we decrement this value so that sequence.currval will point to 40? that is in next insert values will go as 40,41,42...
thanks
chimnay
|
|
|
|
Re: alter sequence [message #216985 is a reply to message #216960] |
Wed, 31 January 2007 03:00 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
Before you continue on this (yes, it IS possible), ask yourself why you want this.
If you think you can create gap-free sequences, forget it. If you use a sequence, in the end you either end up with gaps, or with a single-user system.
SQL> create sequence faq_seq
2 nocache;
Sequence created.
SQL>
SQL> declare
2 l number;
3 begin
4 for i in 1..1000
5 loop
6 select faq_seq.nextval
7 into l
8 from dual;
9 end loop;
10 end;
11 /
PL/SQL procedure successfully completed.
SQL> select faq_seq.nextval from dual;
NEXTVAL
----------
1001
SQL> alter sequence faq_seq increment by -50;
Sequence altered.
SQL> select faq_seq.nextval from dual;
NEXTVAL
----------
951
SQL> alter sequence faq_seq increment by 1;
Sequence altered.
SQL> select faq_seq.nextval from dual;
NEXTVAL
----------
952
|
|
|
|