创建表
create table demo(
did varchar2(20) constraint pk_demo primary key,
dname varchar2(20),
bumen varchar2(100)
)
创建自增ID,名称为:表名_字段名_SEQ
create sequence demo_did_seq minvalue 1 nomaxvalue increment by 1 start with 1 nocache;
为Insert操作创建触发器,无需在sql语句里写NEXTVAL,名称为表名_INS_TRG
create or replace trigger demo_ins_trg
before insert
on demo
for each row when(new.did is null)
begin
select demo_did_seq.nextval into :new.did from dual;
end;
/