About Oracle increment sequence of

1. Create and modify increment sequence

- - syntax to create a sequence of
 [. The User] the Create Sequence sequence_name
    [by the n-INCREMENT]
    [Start with the n-]
    [the n-MAXVALUE | NOMAXVALUE]
    [the n-MINVALUE | NOMINVALUE];
   
- modify the sequence grammar -
the ALTER Sequence [the User .] sequence_name
    [by the n-INCREMENT]
    [the n-MAXVALUE | NOMAXVALUE]
    [the n-MINVALUE | NOMINVALUE]

Sequence Parameter Description
INCREMENT BY: Specifies the interval between the sequence number, this value may be positive or negative integers, but not to zero. Ascending sequence. When this clause is omitted, the default value of 1.
START WITH: specifies a sequence number generated first. When ascending, the sequence may begin with a value larger than the minimum value, the minimum value is the default sequence. For values in descending order, the sequence may be less than the maximum starts, the maximum default value of the sequence.
MAXVALUE: Specifies the maximum sequence generated.
NOMAXVALUE: 1027 specify the maximum ascending, descending specified maximum value -1.
MINVALUE: minimum specified sequence.
NOMINVALUE: Specifies the minimum value of 1 is ascending. Descending to specify the minimum value is -1026.

2. Use sequence

- Create a sample table -
Create Table Student (
    stuId Number (. 9) Not null,
    stuname VARCHAR2 (20 is) Not null,
    stuMsg VARCHAR2 (50) null
)
 
  - create a sequence Student_stuId_Seq -
 Create Sequence Student_stuId_Seq
 INCREMENT. 1 by
 Start. 1 with
 1 MINVALUE
 MAXVALUE 999999999;
 
 - change the sequence Student_stuId_Seq--
 the ALTER sequence Student_stuId_Seq
    INCREMENT by 2 
    MINVALUE 1
    MAXVALUE 9999999;
 
 - obtaining sequence increment ID -
 the SELECT Student_stuId_Seq.Nextval "increment sequence ID" from Dual;
 
 - deleted sequence - -
 drop sequence Student_stuId_Seq;
 
 - calling sequence, inserting data Student -
 insert into Student (stuId, Stuname) values (Student_stuId_Seq.Nextval, ' John Doe');
 insert into Student (stuId, Stuname) values (Student_stuId_Seq.Nextval, ' John Doe');
 - insertion of data query -
 SELECT * from Student

3. The two fields sequences

(1) nextval: When acquiring nextval sequence, it obtains the current value of the sequence, and is incremented once.

(2) currentval: When acquiring currentval sequence, obtains the current value of the sequence will not be incremented.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/160194.htm