In an Oracle database, setting ID auto-increment is not as simple as MySQL, and a sequence needs to be set in Oracle.
Now give the way, specifically as follows:
First step: Create a table
CREATE TABLE Contestdb ( TID number () PRIMARY KEY, teamnum varchar () null, marknum varchar (+)
Step two: Set ID self-increment
The first way: do not use triggers
1 CREATE SEQUENCE seq_tid; 2 INSERT into Contestdb VALUES (Seq_tid. Nextval, ' B20007009 ', ' B001 '); 3 INSERT into Contestdb VALUES (Seq_tid. Nextval, ' B20007010 ', ' B003 ');
Second way: Using the trigger Trigger
1--Customizing a sequence2 Create sequence Contestdb_sequence3Increment by 1--every time I add a few, I'm adding 1 each time.4Start with 1--counting starting from 15Nomaxvalue--do not set the maximum value6Nocycle--keep accumulating, not looping7NoCache--do not build buffers8--Create a trigger9 CREATE TRIGGER Contestdb_triggerTen before INSERT on Contestdb One For each ROW AWhen (New. TID isNULL) --start the trigger to generate the TID number only when the TID is empty - begin -Select Contestdb_sequence.nextval into:New. TID from Sys.dual; the end; - -Insert into CONTESTDB (teamnum,marknum) VALUES (' A20007013 ', ' A002 '); - +Insert into CONTESTDB (teamnum,marknum) VALUES (' A20007014 ', ' A003 ');
Oracle database Creation table and primary key auto-increment