行级的触发器代码中不能操作该表,包括select,所以报错!
当然解决方法就是要根据原因了,正因为限定了行级触发器的操作,只能选择表级的触发器了,但是在表级的触发器又不能获得:new和:old的值,那就只能采取两种触发器并用的方法了,并且还要包或者临时表加以辅助.
首先在行级触发器中将所需的,:new或者:old的值,写到包或者临时表中
然后在表级触发器中处理包或者临时表中已经写入的数据,操作成功后可以按照需求再删除临时表的数据.
下面是一个实例:
-- 创建一个临时表
- create global temporary table TEMP_TEMP
- (
- NOTICEID NUMBER(10),
- VERSION NUMBER(10)
- )
- on commit preserve rows;
--存储过程
- create or replace trigger savetempvalue
- after insert or delete on notice_comment_data
- for each row
- begin
- insert into temp_temp values(:new.noticeId,:new.version);
- end savetempvalue;
--主存储过程
- create or replace trigger UpdateReplyCount
- after insert or delete on notice_comment_data
- declare
- t_noticeId notice_comment_data.noticeid%type;
- t_version notice_comment_data.version%type;
- begin
- select noticeId,version into t_noticeId,t_version from temp_temp;
- update notice_data
- set replyCount=(select count(*) from notice_comment_data
- where notice_comment_data.noticeid=t_noticeId and version=t_version )
- where notice_data.noticeid=t_noticeId
- AND notice_data.version=t_version;
- end UpdateReplyCount;
转载于:https://blog.51cto.com/huqianhao/954544