请各位大侠帮看一下这个oracle触发器那里出错了

ale12 2012-05-15 09:33:07
create or replace trigger test1
after insert or update or delete
on libfile2
for each row
--declare
-- PRAGMA AUTONOMOUS_TRANSACTION;
begin
if deleting then
declare
vol_ownervol libvol2.keyword%type;
file_keyword libfile2.keyword%type;
begin
select :old.ownervol into vol_ownervol from dual;
-- select :old.keyword into file_keyword from dual;

update libvol2 set f2=(select sum(f8) from libfile2 where ownervol=vol_ownervol),f3=(select count(*) from libfile2 where ownervol=vol_ownervol) where libvol2.keyword = vol_ownervol;

--commit;
end;

else
declare
vol_ownervol libvol2.keyword%type;
file_keyword libfile2.keyword%type;

begin
select :new.ownervol into vol_ownervol from dual;
--select :new.keyword into file_keyword from dual;
update libvol2 set f2=(select sum(f8) from libfile2 where ownervol=vol_ownervol),f3=(select count(*) from libfile2 where ownervol=vol_ownervol) where libvol2.keyword = vol_ownervol;

--commit;
end;
end if;
end;
能正常编译;但触发时出错:ora-04091 表xx发生了变化,触发器/函数不能读它
...全文
96 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
APHY 2012-05-16
  • 打赏
  • 举报
回复
分段排除下不难吧~
baiwenyu 2012-05-16
  • 打赏
  • 举报
回复
可能是触发器中的逻辑在触发器本身还没有执行完时,又导致了重新触发;
你 update libvol2 ,是否在libvol2 也有触发器,导致更改 libfile2。
ale12 2012-05-16
  • 打赏
  • 举报
回复
谢谢各位了,问题我找到了:行触发器中不能对基表进行查询操作。我上面就犯了这个错。
forgetsam 2012-05-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

如果我用自治事务处理,就会出现,我更新libfile2两次libvol2才更新一次。呵呵,理起来有点糊涂,还请大侠们多指点一下
[/Quote]

这种事尽可能用存储过程做。
ale12 2012-05-16
  • 打赏
  • 举报
回复
如果我用自治事务处理,就会出现,我更新libfile2两次libvol2才更新一次。呵呵,理起来有点糊涂,还请大侠们多指点一下
forgetsam 2012-05-16
  • 打赏
  • 举报
回复
和触发器无关,是你的逻辑没理清。

举个最简单例子:我修改某列数据时,要求这数值不能大于此列平均值,那么我计算平均数时包含了当前行,那我应该取何时的数据?这和Oracle的事务处理逻辑有关。

1 用你注释掉的自治事务处理

2 把逻辑改正。

1,617

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧