pl/sql 编程(十一)

  • 行级DML触发器的创建
create or replace trigger tri_goods 
after insert or update or delete
on goods
for each row
begin
    if inserting then 
       insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('添加的数据',sysdate,:new.goodsid,:new.goodsname,:new.remark,g_modify_id.nextval);
    elsif deleting then 
        insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('删除的数据',sysdate,:old.goodsid,:old.goodsname,:old.remark,g_modify_id.nextval); 
    else
          insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('修改的数据',sysdate,:old.goodsid,:old.goodsname,:new.remark,g_modify_id.nextval);
    end if;  
end;

 

使用when,case……when

create or replace trigger tri_goods2 
after insert or update or delete
on goods2
for each row
when (new.goodsid =100)
begin
    case 
    when  inserting then 
       insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('添加的数据',sysdate,:new.goodsid,:new.goodsname,:new.remark,g_modify_id.nextval);
    when deleting then 
        insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('删除的数据',sysdate,:old.goodsid,:old.goodsname,:old.remark,g_modify_id.nextval); 
    when updating then
          insert into g_modify (oper_type,oper_time,goodsid,goodsname,remark,g_modify_id)
              values('修改的数据',sysdate,:old.goodsid,:old.goodsname,:new.remark,g_modify_id.nextval);
    end case;  
end;

 

 

posted @ 2012-04-19 22:59  shuaisam  阅读(163)  评论(0编辑  收藏  举报