As we all know, this is very pit, especially used in MySQL's Self-increment field settings, the result is not in Oracle. Oh,no
I am using the 12c version, it has a new feature, you can set the self-increment sequence, in the creation table is, set the ID as the self-increment sequence
CREATE TABLE T
(
ID number generated by default as identity (start with 1 increment by 1),
Name VARCHAR2 (20),
Password VARCHAR2 (20),
Constraint pk_t Primary Key (Id)
);
Very worried Mulberry is a companion with 11g, that can only be achieved by sequence + trigger;
Create a table
-create Table T
(
ID number,
Name VARCHAR2 (20),
Password VARCHAR2 (20),
Constraint pk_t Primary Key (Id)
);
CREATE SEQUENCE seq_t----------------/* Sequence name */
INCREMENT by 1----------------/* self-increment 1*/
Start with 1----------------/* Starting from 1 */
Nomaxvalue----------------/* Does not have a maximum value */
Nocycle
NOCACHE;
Create TRIGGER tri_t before------------------/* Creating trigger */
INSERT on T for each ROW if (new.id is null)
Begin
Select Seq_t.nextval into:new.id from dual;
End
Self-increment field settings in Oracle