首页 > 数据库技术 > 详细

oracle触发器

时间:2018-02-06 17:27:07      阅读:244      评论:0      收藏:0      [点我收藏+]

基础就不说了,放一个用的东西比较多的触发器,以后方便看

create or replace trigger test1_update
after update
on test1
for each row
  
declare
pragma autonomous_transaction;
  field VARCHAR2(2000);
  sum1 integer;
begin
  select count(1) into sum1 from changelog where id=:new.id and table_name=‘test1‘;
  if sum1<>0 then
    select update_field into field from changelog where id=:new.id and table_name=‘test1‘;
  end if;
  if updating (‘clum1‘) then
    select field||‘clum1,‘ into field from dual;
  end if;
  if updating (‘clum2‘) then
     select field||‘clum2,‘ into field from dual;
  end if;
  insert into changelog values(:old.id,‘test1‘,‘0‘,‘update‘,field,sysdate,‘‘,‘‘,‘‘);
end;

输出语句是dbms_output.put_line(‘name字段被修改‘);

方便查看变量的值对不对。

oracle触发器

原文:https://www.cnblogs.com/IceBlueBrother/p/8423148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!