连续创建多个Oracle触发器失败,单个创建才成功的解决方法
连续创建多个Oracle触发器失败,单个创建才成功的解决方法
1、当我连续执行创建多个触发器时,总是报编译通过,但存在警告或错误。如下:
create or replace trigger tr_advert
before insert on jcms_advert
for each row
begin
select seq_advert.nextval into :new.id from dual;
end;
create or replace trigger tr_advert_type
before insert on jcms_advert_type
for each row
begin
select seq_advert_type.nextval into :new.id from dual;
end;
这种创建是失败的,因为触发器需要先编译,每创建一个触发器,需要以“/”结束,然后才能执行下一个。
2、正确的创建方法如下:
create or replace trigger tr_advert
before insert on jcms_advert
for each row
begin
select seq_advert.nextval into :new.id from dual;
end;
/
alter trigger tr_advert enable;
create or replace trigger tr_advert_type
before insert on jcms_advert_type
for each row
begin
select seq_advert_type.nextval into :new.id from dual;
end;
/
alter trigger tr_advert_type enable;