A sequence is an object in oracle database i.e used to generate
a number sequence. This can be useful when you need to create a unique number
that acts as the primary key.
E.g:-
Create Sequence SEQ_TEST
MinValue 1
MaxValue 999999999
Increment by 1
Start With 1
NoCache NoOrder NoCycle;
Note:-
Here SEQ_TEST is the name of the sequence, then after we need to set the
parameter according to our conditions and requirements.
Call the Sequence
in select statement:-
Query:- select
SEQ_TEST1.nextval from dual;
Check the list of sequences created in database user:
Query:- Select * from User_Sequences;
Conditions:-
* When we have a requirement to change the sequence increment number from 1 to increment by 5 then
* When we have a requirement to change the sequence increment number from 1 to increment by 5 then
Query:- Alter Sequence SEQ_TEST increment by 5;
*When we a condition to restart the sequence then
Query:- Alter Sequence SEQ_TEST Restart With 1;
* In this sequence code we have set NoCache, Suppose we have set Cache 5 then it will store the upcoming 5 number in the memory and the LAST_NUMBER of the sequence as per the cache i.e +5 it will update automatically.
Query to update or change the cache value in sequence:-
Alter Sequence SEQ_TEST Cache 5; ----> (Here it will set the cache 5 in your sequence)
*When we a condition to restart the sequence then
Query:- Alter Sequence SEQ_TEST Restart With 1;
* In this sequence code we have set NoCache, Suppose we have set Cache 5 then it will store the upcoming 5 number in the memory and the LAST_NUMBER of the sequence as per the cache i.e +5 it will update automatically.
Query to update or change the cache value in sequence:-
Alter Sequence SEQ_TEST Cache 5; ----> (Here it will set the cache 5 in your sequence)
No comments:
Post a Comment