"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;
beginselect 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里面然后又报出“检测到活动的自治事务处理,已经回退”什么问题,大家帮忙看看

解决方案 »

  1.   

    [code]
    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;
    beginselect 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;[/code]
    以上是原先的代码,每次都在select那里出错,提示表发生了变化,触发器不能读它。在网上找了很多,看到一个用自治事务的,就加了 “PRAGMA AUTONOMOUS_TRANSACTION;”在declare里面然后又报出“检测到活动的自治事务处理,已经回退"
    什么问题,大家帮忙看看