Oracle中序列(SEQUENCE)的使用一例
Oracle中序列(SEQUENCE)的使用一例
曾经在触发器中使用序列(SEQUENCE):
create or replace trigger TRI_SUPPLIER before insert on SUPPLIER for each row begin select seq_supid.NEXTVAL into:new.supcode from dual; select seq_supid.CURRVAL into:new.supID from dual; end;
显然,忽略了并发,修改后如下:
create or replace trigger TRI_SUPPLIER before insert on SUPPLIER for each row declare v_supval number(20); begin select seq_supid.NEXTVAL into v_supval from dual; select v_supval into:new.supcode from dual; select v_supval into:new.supID from dual; end;