oracle触发器的问题

lushan1314 2011-05-11 07:25:03
"java"
create or replace trigger test02
after update on table1
for each row
when (new.status='f' or new.status = 'g')
declare
theTrigerTaskId table1.id%type;
begin

select id into theTrigerTaskId from table1 where task_id = :new.id;//这张表是通过task_id自关联的,我的逻辑就是想在新的任务状态发生改变时,改变老的那条任务状态
if :new.status = 'f' then
update table1 set status='c' where id = theTrigerTaskId;
elsif :new.status = 'g' then
update table1 set status='d' where id = theTrigerTaskId;
end if;
end test02;

以上是原先的代码,每次都在select那里出错,提示表发生了变化,触发器不能读它。。。。

在网上找了很多,看到一个用自治事务的,就加了 “PRAGMA AUTONOMOUS_TRANSACTION;”在declare里面

然后又报出“检测到活动的自治事务处理,已经回退

什么问题,大家帮忙看看
...全文
70 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lushan1314 2011-06-13
  • 打赏
  • 举报
回复
rdfd
友林 2011-06-12
  • 打赏
  • 举报
回复
o yeah
lushan1314 2011-05-11
  • 打赏
  • 举报
回复
在线等,求大家帮忙,如果这样写不可以,那么有什么方式吗?

我需要在插入的时候更新本表,能怎么办呢?

这里肯定是锁定了,不能读,可是有什么好的解决方案吗?

我很困扰,这个还必须实现 ,没有其他通过程序解决的办法,我之前没碰过触发器,大牛啊,帮帮俄吧
lushan1314 2011-05-11
  • 打赏
  • 举报
回复

create or replace trigger test02
after update on table1
for each row
when (new.status='f' or new.status = 'g')
declare
theTrigerTaskId table1.id%type;
begin

select id into theTrigerTaskId from table1 where task_id = :new.id;//这张表是通过task_id自关联的,我的逻辑就是想在新的任务状态发生改变时,改变老的那条任务状态if :new.status = 'f' then
update table1 set status='c' where id = theTrigerTaskId;
elsif :new.status = 'g' then
update table1 set status='d' where id = theTrigerTaskId;
end if;
end test02;

以上是原先的代码,每次都在select那里出错,提示表发生了变化,触发器不能读它。。。。

在网上找了很多,看到一个用自治事务的,就加了 “PRAGMA AUTONOMOUS_TRANSACTION;”在declare里面

然后又报出“检测到活动的自治事务处理,已经回退"
什么问题,大家帮忙看看

3,491

社区成员

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

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