Oracle uses triggers to implement auto-increment columns, and oracle uses triggers
Oracle uses triggers to implement auto-increment Columns
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. 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 sequencetest_user_seq start with 1 maxvalue 9999999999 increment by 1;
3. Create a trigger
Create or replace
Triggertest_user_trigger
Before insert ontest_user
For each row
Begin
Selecttest_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;