假设有表  testms ,testtb,testlist 
结构如下:
  testms: recno ,col1,col2,col3
  testtb :recno,testmsrecno(和testms的recno关联),col4,col5
  testlist:recno testtbrecno(和testtb的recno关联),col6,col7现在我的需求如下:
   当testtb的col4的字段的值变为Y时,触发触发器:
  把testtb表中所有testmsrecno为:new.testmsrecno而且对应testlist的col6不为空的记录的col4的字段也变为Y
该怎么写触发器?
或者不用触发器,用其他办法来完成也好,但是在web页面中写的话感觉麻烦,
还有问下 当在testtb 表建立update trigger那么是不是不可在trigger中对此表进行select ,update delete的操作?

解决方案 »

  1.   

    1.可以在程序中实现:
    update testb b set col4='Y'
    where b.recno in
    (
        select a.recno from testb a,testlist where a.recno=testtbrecno   and col6 is not null
    )2.用自治事务   
      create   or   replace   trigger   tr_test   
      after   insert   on   t1   
      for   each   row   
      declare   
          pragram   autonomous_transaction;   
      begin   
          --   执行代码  
        if :new.col4='Y' then
           update testb b set col4='Y'
           where b.recno in
          (
             select a.recno from testb a,testlist where a.recno=testtbrecno and          testtbrecno=:new.testmsrecno and col6 is not null
           )
      end if;
          commit;   
      end;   
      

  2.   

    create  or  replace  trigger  tr_test  
      after  insert  on  t1  t1是哪个表?是不是testtb呢?
      

  3.   

    我写update 触发器
     create  or  replace  trigger  tr_test  
      befor update of col4 on  testtbdeclare  
          pragram  autonomous_transaction;  
      begin  
          --  执行代码  
        if :new.col4='Y' then 
          update testb b set col4='Y' 
          where b.recno in 
          ( 
            select a.recno from testb a,testlist where a.recno=testtbrecno and          testtbrecno=:new.testmsrecno and col6 is not null 
          ) 
      end if; 
          commit;  
      end;  
    这样的话会报等待资源遇到一个死锁,因为 update testb b set col4='Y' 
          where b.recno in 
          ( 
            select a.recno from testb a,testlist where a.recno=testtbrecno and          testtbrecno=:new.testmsrecno and col6 is not null 
          ) 
     又触发了触发器.这种情况有没有办法解决呢?
      

  4.   

    commit;去掉,create  or  replace  trigger  tr_test  
      before insert of col4 on  testtb 改成这个试试!对UPDATE不执行!如果确认要UPDATE 要执行,那换成在程序端判断!
      

  5.   

    整的太复杂了
    以下可以参考一下:
    create  or  replace  trigger  tr_test  
      befor update of col4 on  testtb referencing old as old new as new
    for each row
    when 加入你的条件。