What Is Sequence
What Is Sequence
1. What is Sequence?
A sequence is an object in Oracle that is used to generate a number which would be sequence. i.e.
you can create an autonumber field by using sequences. This can be useful when you need to
create a unique number to act as a primary key.
Sequence Syntax
Example:-
With respect to a sequence, the cache option specifies how many sequence values will be stored in
memory for faster access.
The downside of creating a sequence with a cache is that if a system failure occurs, all cached
sequence values that have not be used, will be "lost". This results in a "gap" in the assigned
sequence values. When the system is up (comes back up), Oracle will cache new numbers from
where it left off in the sequence, ignoring the so called "lost" sequence values.
Nocache means that none of the sequence values are stored in memory. This option may sacrifice
some performance; however, you should not encounter a gap in the assigned sequence values.
Using the ALTER SEQUENCE command you can change the LASTVALUE for an Oracle
sequence.
For example, if the last value used by the Oracle sequence was 100 and you would like to reset
the sequence to serve 225 as the next value. You would execute the following commands.