当前位置: 代码迷 >> Oracle开发 >> oracl触发器
  详细解决方案

oracl触发器

热度:63   发布时间:2016-04-24 06:40:39.0
求一个oracl触发器
当两张表的两个不同字段值相等,把第二张表的另一个字段置为true的触发器怎么写?
------解决方案--------------------

create or replace trigger tri_upd
after insert on tablename1
for each row
declare
cursor mycur  is select * from tablename2;
myrec tablename2%rowtype;
begin
open mycur;--打开游标
fetch mycur into myrec;
while mycur%found loop 
    fetch mycur into myrec;
    if(myrec.columnname2=:new.columnname1) then
    update tablename2 set flag=true where id=myrec.id;
    commit;
    end if;
    end loop;
close mycur;
end;