I have been using SQL Server for database development. Recently, I started to learn about oracle because I used Oracle databases for new projects.
After learning for a while, I found that there is still a big difference between SQL Server and Oracle. First, I couldn't find the self-growth field that I used very well in SQL Server in Oracle. My friend said that the sequence can be used. So I checked the data and sorted out the following example:
1. Create a test data table
Create Table Test
(
ID number,
Name varchar2 (20 ),
Primary Key (ID)
);
2. Create a sequence
Create sequence seq_test;
3. Create a trigger
Create or replace trigger autoincrement
Before insert on Test
For each row
When (New. ID is null)
Begin
Select seq_test.nextval into: New. ID from dual;
End;
/
4. insert data
Insert into test (name) values ('name1 ');
5. view the insert result
Select * from test;