From http://9494.iteye.com/blog/48553
Introduction:
Generally, the primary keys of tables increase automatically. in Oracle, sequence-based auto-growth is more suitable.
1. Sequence creation format:
Create sequence name
Increment by 1
Start with 100
Max value 99999999
Nominvalue
Nocycle
Nocache
Noorder
Go
2. Application
1> View the sequence value:
Select sequence. nextval (sequence. currval) from dual
2> when inserting data into a table:
Insert into table name values (sequence name. nextval, column 1 value, column 2 value ,...);
Insert into Table Name (sequence name. currval, column 1 value, column 2 value ...);
3> In a stored process, get the value to a parameter:
Select sequence name. nextval into parameter name from dual;
Call this parameter where the serial number is reused.
Implementation Method 2: (using triggers)
Create or replace trigger name
Before insert or update on table
For each row
Begin
Select sequence. nextval into: New. N from dual;
End; // There must be;
Trigger created