<ul><li>A sequence is a user created  data base object  that can be shared by multiple users to generate unique integer. <...
<ul><li>Create sequence  s equencename [ increment by n start with n maxvalue n/ nomaxvalue  minvalue n/ nominvalue cycle/...
<ul><li>SEQUENCENAME:I t  is the name   of the sequence.  </li></ul><ul><li>INCREMENT BY N:  specifies the interval betwee...
<ul><li>create sequence  seq1   increment by 1 start with 1; </li></ul><ul><li>select  seq1.nextval  from dual; </li></ul>...
<ul><li>MAXVALUE:  specifies the maximum sequence value. </li></ul><ul><li>MINVALUE:  specifies the minimum sequence value...
<ul><li>NOMAXVALUE:  specifies a maximum value of 10^27 for an ascending sequence or -1 for descending sequence. </li></ul...
<ul><li>alter sequence  seq1  nomaxvalue nominvalue ; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>select  seq1.nextval  fr...
<ul><li>CYCLE:  specifies that the sequence continues to generate repeat values after reaching either its maximum value. <...
<ul><li>Create sequence  seq2  increment by 1 start with1 maxvalue 21  cycle; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>...
<ul><li>create sequence  seq2  increment by 1 start with 1 maxvalue 2  nocycle ; </li></ul><ul><li>OUTPUT: </li></ul><ul><...
<ul><li>CACHE:  specifies how many values of a sequence oracle pre-allocates and keeps in memory for faster access. </li><...
<ul><li>Create sequence  seq1   increment by 1 start with 1  cache ; </li></ul><ul><li>OUTPUT </li></ul><ul><li>Select  se...
<ul><li>NEXTVAL: </li></ul><ul><li>The nextval pseudocolumns is used to extract successive nos from a specified sequence. ...
<ul><li>Select  seq1.nextva l from dual; </li></ul><ul><li>And </li></ul><ul><li>Insert into tablenm values( seq1.nextval ...
<ul><li>CURRVAL: </li></ul><ul><li>The currval pseudocolumn is used to refer to sequence number that the current user has ...
<ul><li>create sequence seq2 increment by 1 start with 1 maxvalue 4 cycle; </li></ul>
<ul><li>ERROR:  number to CACHE must be less than one cycle. </li></ul><ul><li>In the above query maxvalue should be above...
<ul><li>So if you want above query to work than give any maxvalue, cycle and cache whose value will be  less than  max </l...
 
Upcoming SlideShare
Loading in...5
×

Sequences

755

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
755
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sequences

  1. 2. <ul><li>A sequence is a user created data base object that can be shared by multiple users to generate unique integer. </li></ul><ul><li>A typical usage of sequence is to create a primary key value, which must be unique. </li></ul><ul><li>Sequence numbers are stored and generated independently of tables. Therefore the same sequence can be used for multiple tables. </li></ul>
  2. 3. <ul><li>Create sequence s equencename [ increment by n start with n maxvalue n/ nomaxvalue minvalue n/ nominvalue cycle/ nocycle cache n/ nocache order/ noorder]. </li></ul><ul><li>Sequences is used in create , Insert, select, alter ,drop statement. </li></ul><ul><li>The start value of sequence cannot be altered. </li></ul>
  3. 4. <ul><li>SEQUENCENAME:I t is the name of the sequence. </li></ul><ul><li>INCREMENT BY N: specifies the interval between the sequences nos where n is an integer. The default vale is 1. </li></ul><ul><li>START WITH: specifies the first sequence number to be generated. </li></ul>
  4. 5. <ul><li>create sequence seq1 increment by 1 start with 1; </li></ul><ul><li>select seq1.nextval from dual; </li></ul><ul><li>Output: </li></ul><ul><li>NEXTVAL ---------- </li></ul><ul><li>1 </li></ul>
  5. 6. <ul><li>MAXVALUE: specifies the maximum sequence value. </li></ul><ul><li>MINVALUE: specifies the minimum sequence value. </li></ul><ul><li>EXAMPLE: </li></ul><ul><li>alter sequence seq1 minvalue 1 maxvalue 2; </li></ul><ul><li>select seq1.nextval from dual; </li></ul><ul><li>2 </li></ul>
  6. 7. <ul><li>NOMAXVALUE: specifies a maximum value of 10^27 for an ascending sequence or -1 for descending sequence. </li></ul><ul><li>NOMINVALUE: specifies a maximum value of 1 for an ascending sequence or (-10)^26 for descending sequence. </li></ul>
  7. 8. <ul><li>alter sequence seq1 nomaxvalue nominvalue ; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>select seq1.nextval from dual; </li></ul><ul><li>1 </li></ul><ul><li>2 </li></ul><ul><li>3 </li></ul><ul><li>. </li></ul><ul><li>. </li></ul><ul><li>. </li></ul>
  8. 9. <ul><li>CYCLE: specifies that the sequence continues to generate repeat values after reaching either its maximum value. </li></ul><ul><li>NOCYCLE: specifies that the sequence cannot generate more values after reaching either its maximum value. </li></ul>
  9. 10. <ul><li>Create sequence seq2 increment by 1 start with1 maxvalue 21 cycle; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>Select seq2.nextval from dual; </li></ul><ul><li>1 </li></ul><ul><li>2 </li></ul><ul><li>. </li></ul><ul><li>. </li></ul><ul><li>21 </li></ul><ul><li>1 </li></ul>
  10. 11. <ul><li>create sequence seq2 increment by 1 start with 1 maxvalue 2 nocycle ; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>Select seq2.nextval from dual; </li></ul><ul><li>1 </li></ul><ul><li>2 </li></ul><ul><li>Error:exceed maximum value. </li></ul>
  11. 12. <ul><li>CACHE: specifies how many values of a sequence oracle pre-allocates and keeps in memory for faster access. </li></ul><ul><li>NOCACHE: specifies that values of a sequence are not pre-allocated. </li></ul>
  12. 13. <ul><li>Create sequence seq1 increment by 1 start with 1 cache ; </li></ul><ul><li>OUTPUT </li></ul><ul><li>Select seq1.nextval from dual; </li></ul><ul><li>1 </li></ul><ul><li>2 </li></ul><ul><li>3 </li></ul><ul><li>. </li></ul><ul><li>. </li></ul>
  13. 14. <ul><li>NEXTVAL: </li></ul><ul><li>The nextval pseudocolumns is used to extract successive nos from a specified sequence. </li></ul><ul><li>We must qualify nextval with the seq.name. </li></ul><ul><li>When we reference seq.nextval, a new sequence number is generated and the current sequence number is placed in currval. </li></ul>
  14. 15. <ul><li>Select seq1.nextva l from dual; </li></ul><ul><li>And </li></ul><ul><li>Insert into tablenm values( seq1.nextval ,’abc’); </li></ul>
  15. 16. <ul><li>CURRVAL: </li></ul><ul><li>The currval pseudocolumn is used to refer to sequence number that the current user has just generated. </li></ul><ul><li>Nextval must be used to generate a sequence number in the current users session before currval can referrenced. </li></ul><ul><li>When seq.currval is referenced, the last value returned to that users process is displayed. </li></ul>
  16. 17. <ul><li>create sequence seq2 increment by 1 start with 1 maxvalue 4 cycle; </li></ul>
  17. 18. <ul><li>ERROR: number to CACHE must be less than one cycle. </li></ul><ul><li>In the above query maxvalue should be above 20. </li></ul><ul><li>It should be always more than 20 because oracle caches 20 sequences numbers by default. </li></ul>
  18. 19. <ul><li>So if you want above query to work than give any maxvalue, cycle and cache whose value will be less than max </li></ul><ul><li>EXAMPLE: </li></ul><ul><li>create sequence seq2 increment by 1 start with 1 maxvalue 4 cycle cache 3 ; </li></ul><ul><li>OUTPUT: </li></ul><ul><li>1 </li></ul><ul><li>2 </li></ul><ul><li>3 </li></ul><ul><li>4 </li></ul><ul><li>1 </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×