When inserting, use sequence to automatically generate the primary key for the table

When inserting data, use sequence to automatically generate the primary key for the table

1. Create a sequence

  create   sequence   sequence_name   
  minvalue   1   
  maxvalue   99999999
  start   with   1   
  increment  by 1   

  cache   20


2. Create a trigger and use sequence to automatically add a primary key to the table

create or replace trigger trg_insert_id 
before insert on o_app_api 
for each row 
BEGIN 
select sequence_name.nextval into :new.id from dual; 
END; 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324643724&siteId=291194637