0 0

oracle触发器问题20

 

id pid
1 0
2 1
3 1

比如oracle表中数据是这样的,怎么定义触发器,比如,更改id=1的id时,使id=2,3的行的pid跟着更改

还有删除id=1的行,pid为1的行也删除

2012年8月14日 19:46

2个答案 按时间排序 按投票排序

0 0

采纳的答案

create or replace trigger trigger_test
  after update or delete on whisky
  referencing old as old new as new
  for each row
declare
  PRAGMA AUTONOMOUS_TRANSACTION;
  -- local variables here
begin
  --for update
  if updating then
    update whisky set pid = :new.id where pid = :old.id;
  else
    --for delete
    delete from whisky where pid = :old.id;
  end if;
  commit;
end trigger_test;


我测试是ok的,不知是否满足你的需求。。。

2012年8月15日 09:19
0 0

create or replace trigger trig_test_tb
after delete on test_tb
for each row
declare
pragma autonomous_transaction;
begin
  delete from test_tb where pid=:old.id;
  commit;
end;

2012年8月14日 20:59

相关推荐

Global site tag (gtag.js) - Google Analytics