dzq584462393
dzq584462393
2012-08-14 19:46

oracle触发器问题

已采纳

 

id pid
1 0
2 1
3 1

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • liuyinhuan0409 liuyinhuan0409 9年前

    [code="sql"]
    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;

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

    点赞 评论 复制链接分享
  • Dead_Knight Dead_Knight 9年前

    [code="java"]
    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;
    [/code]

    点赞 评论 复制链接分享

相关推荐