Both SQL server and mysql can set the primary key auto-increment, while the oracle primary key does not have the auto-increment attribute, which can be achieved through the following two methods:
1. Create a sequence through a trigger
Create Sequence
Java code
Create sequence messageid minvalue 1 maxvalue start with 1 increment by 1 NOCACHE;
Create a trigger
Java code
Create or replace trigger ID_TRIGGER
Before insert on box for each row declare newId NUMBER (18, 0 );
Begin select messageid. nextval INTO newId FROM dual;: new. Id: = newId;
END;
2. Create a sequence using the id obtained by the sequence in an SQL statement.
Create Sequence
Java code
Create sequence messageid minvalue 1 maxvalue start with 1 increment by 1 NOCACHE;
Use in SQL statements
A. Obtain the id:
Java code
Select messageid. nextval FROM dual;
B. Direct use:
Java code
Insert into box (id, name) VALUES (MESSAGEID. nextval, "sa ")
Author "roc08"