oracle觸發器
create or replace trigger imagtrig.tr_au_image_file_index
after update on image_file_index
referencing new as new old as old
for each row
declare
v_trigger_user varchar2(50);
v_trigger_date date;
v_trigger_name varchar2(30) := 'tr_au_image_file_index';
cursor c_switch(cp_switch varchar2) is
select status
from image_tr_switch
where trigger_name = upper(v_trigger_name)
and switch_for = cp_switch;
v_status image_tr_switch.status%type;
v_sqlcode varchar2(6);
v_sqlerrm varchar2(200);
v_error_comment varchar2(300);
--序列號
v_seq_no varchar2(20);
begin
v_error_comment := 'before get_user';
--獲取使用者
v_trigger_user := pub_sys_package.get_user();
v_trigger_date := sysdate;
open c_switch('col_log');
fetch c_switch into v_status;
if c_switch%found and v_status='1' then
select seq_image_index_change_log_id.nextval into v_seq_no from dual;
v_error_comment:='column log bar_code';
if (nvl(:old.bar_code,'~') <> nvl(:new.bar_code,'~')) then
--記錄bar_code變更字段資訊
insert into image_index_change_log(log_id,change_type,table_name,table_primary_key,trigger_name,operate_user,
operate_date,other_old_value,other_new_value,remark)
values(v_seq_no,
'01',
'image_file_index',
:new.bar_code,
'tr_au_image_file_index',
v_trigger_user,
v_trigger_date,
'bar_code='||:old.bar_code,
'bar_code='||:new.bar_code,
'bar_code');
end if;
--#log_content#
end if;
--出錯處理
exception
when others then
v_sqlcode :=sqlcode;
v_sqlerrm :=substr(sqlerrm,1,200);
insert into image_tr_error_log(
error_no --系統錯誤**
,error_message --系統錯誤資訊
,trigger_name --出錯的trigger
,trigger_user --出錯的使用者
,trigger_date --出錯的時間
,error_comment --出錯詳細資訊
)values(v_sqlcode
,v_sqlerrm
,upper(v_trigger_name)
,v_trigger_user
,v_trigger_date
,v_error_comment
);end tr_au_image_file_index;
mysql 觸發器 編寫 MySQL編寫觸發器
觸發器語法示例 create trigger trigger name trigger time trigger event on tb name for each row trigger stmt trigger name 觸發器的名稱 tirgger time 觸發時機,為before或者aft...
Sql觸發器的編寫
觸發器新增到多個表 create trigger trigger insert on dbo company for insert asinsert company del select top1 from company order byid desc 觸發器刪除多個表 create trigge...
ORACLE觸發器 行級觸發器
行級觸發器 本章介紹行級觸發器機制。大部分例子以insert出發器給出,行級觸發器可從insert update delete語句觸發。1 介紹 觸發器是儲存在資料庫已編譯的儲存過程,使用的語言是pl sql,用編寫儲存過程一樣的方式編寫和編譯觸發器。下面在sql plus會話中建立和示例乙個簡單的...