The following articles describe the content of Oracle Auto-increment fields. We all know that Oracle is different from ms SQL, and there is no relevant auto-increment column by default, however, we can create auto-incrementing fields by creating relevant sequences and triggers. The following describes how to create the Oracle Auto-incrementing field Oracle 11g ).
1. Create a TestTable table,
- CREATE TABLE TestTable
- (
- ID NUMBER NOT NULL,
Used for auto-increment Columns
- NAME VARCHAR2(40)
- )
- ;
2. Create a Sequence) and name it SEQ. We recommend that you use the built-in visualization tool to create 'dunk', which is the user name I log on to. Do not copy it all ).
- CREATE SEQUENCE "DUNCAN"."SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999
- INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE ;
3. Create a trigger
- create or replace
- TRIGGER Test_Trr
- BEFORE INSERT ON TestTable
Create a trigger on 'testtable'
- FOR EACH ROW
- BEGIN
- SELECT SEQ.NEXTVAL INTO :new.ID FROM sys.DUAL;
'Nextval = increase the sequence value, then return the sequence Value and insert this value into the ID'
- END;
Now, the auto-increment column in The TestTable table is created. Just insert a piece of data to your colleagues! The above content is an introduction to the implementation of Oracle Auto-increment fields. I hope you will gain some benefits.