Oracle does not have the auto-increment function. mysql and sqlserver use auto_increment and identity () to implement auto-increment respectively. Oracle can only be implemented through sequences,
Oracle does not have the auto-increment function. mysql and sqlserver use auto_increment and identity () to implement auto-increment respectively. Oracle can only be implemented through sequences,
Oracle uses triggers to implement auto-increment Columns
[Date:] Source: Linux Author: neweastsun [Font:]
Oracle does not support auto-increment columns. mysql and SQL server use auto_increment and identity () to implement auto-increment respectively. Oracle can only be implemented through sequences. During each insertion, it is inconvenient to display the sequence value to the auto-increment column. The trigger is used here, in this way, the three databases are syntactically consistent during insertion, facilitating DAO code porting. The following is an Oracle implementation example. The steps are as follows:
1. Create a table
Create tabletest_user (
User_id number (10, 0) primary key,
User_name varchar2 (40)
);
2. Create a sequence
Create sequence test_user_seq start with 1 maxvalue 9999999999 increment by 1;
3. Create a trigger
Create or replace
Trigger test_user_trigger
Before insert on test_user
For each row
Begin
Select test_user_seq.nextval into: new. user_id from dual;
End;
4. insert data
Insert into test_user (user_name) values ('Tom ');
Insert into test_user (user_name) values ('jack ');
5. Test Results
Select * from test_user;