create or replace trigger monthreport after insert on bponderation for each row declare begin delete from bmonth where bmonth.fmonth=to_char(sysdate,'mm'); end 为什么总时提示 ‘ora-04079 无效的触发器说明’而不能保存我用的是10i
将此句 select count(*) into num from bmonth,inserted where bmonth.fbreedid=:new.fbreedid 改成 select nvl(sum(1),-1) into num from bmonth,inserted where bmonth.fbreedid=:new.fbreedid 原因,找不到fbreeddid时会触发一个错误,除非你显式用when ...处理否则改动一下语句把,就OK了。
create or replace trigger monthreport after insert on bponderation for each row declare num number; begin select count(*) into num from bmonth,inserted where bmonth.fbreedid=:new.fbreedid ; if num>0 then insert into bmonth (fyear,fmonth,fcarcount,fbreedid) values(to_char(sysdate,'yyyy'), to_char(sysdate,'mm'),'1',:new.fbreedid ); end if; end monthreport; /
after insert on bponderation
for each row
declare
begin
delete from bmonth
where bmonth.fmonth=to_char(sysdate,'mm');
end
为什么总时提示 ‘ora-04079 无效的触发器说明’而不能保存我用的是10i
select count(*) into num
from bmonth,inserted
where bmonth.fbreedid=:new.fbreedid
改成
select nvl(sum(1),-1) into num
from bmonth,inserted
where bmonth.fbreedid=:new.fbreedid
原因,找不到fbreeddid时会触发一个错误,除非你显式用when ...处理否则改动一下语句把,就OK了。
after insert on bponderation
for each row
declare
num number;
begin
select count(*) into num
from bmonth,inserted
where bmonth.fbreedid=:new.fbreedid ;
if num>0 then
insert into bmonth (fyear,fmonth,fcarcount,fbreedid) values(to_char(sysdate,'yyyy'),
to_char(sysdate,'mm'),'1',:new.fbreedid );
end if;
end monthreport;
/