首先创建一张表:
create table cloud(
id NUMBER(3) PRIMARY KEY,
name VARCHAR2(20),
address VARCHAR2(20)
);
步骤1:创建序列
create sequence autoid
increment by 1
start with 1
minvalue 2
maxvalue 100
/
步骤2:为相应的表创建触发
create or replace trigger trg_cloud
before insert on cloud
for each row --每操作一行就触发一次,默认是表级触发器(无论触发多少行之触发一次)
begin
select autoid.nextval into:new.id from dual;
end;
/