关于触发器
来源:互联网 发布:印度经济知乎 编辑:程序博客网 时间:2024/04/29 15:23
DML触发器
语句触发器:当执行DML语句时被隐含执行的触发器
语法: create (or replace) trigger t_update_A
{BEFORE| AFTER } EVENT1 [OR EVENT2 OR EVENT3]
ON TABLE_NAME
pL/SQL block;
eg:
create or replace trigger tr_sec_emp
before insert or update or delete on emp
begin
if to_char(sysdate,'DY','nls_date_language=AMERICAN')
IN ('SAT','SUN') THEN
raise_application_error(-20001,'不能在休息日改变雇员信息');
end if;
end;
行触发器-----当执行DML语句时,每作用一行被触发一次的触发器,当使用DML语句触发器时,
不能记录列数据的变化,为了审计表数据的变化,就需要使用行触发器
eg: create or replace trigger tr_emp_sal
before update of sal on emp
for each row
begin
if :new.sal<:old.sal then
raise_application_error(-20010,'工资只涨不降');
end if;
end;
限制行触发器:-----在特定条件下执行行触发器,需要使用When子句对触发条件加以限制,
(下面以审计岗位salesman的雇员工资变化为例)
eg: create or replace trigger tr_sal_change
after update or sal on emp
for each row
when (old.job='salesman')
declare
v_temp int;
begin
select count(*) into v_temp from audit_emp_change where name=:old.ename;
if v_temp=0 then
insert into audit_emp_change
values(:old.ename,:old.sal,:new.sal,sysdate);
else
update audit_emp_change
set oldsal_:old.sal,newsal=:new.sal, time=sysdate
where name=:old.ename;
end if;
end;
eg:
CREATE TRIGGER after_IQC_Inspection
after insert on iqcm.iqc_inspection
for each row
declare
v_specid iqc_spec.id%type;
v_subclassno iqc_spec.subclassno%type;
--??????
v_plant iqc_inspec_set.plant%type;
v_grade iqc_inspec_set.geadeno%type;
v_methodno iqc_inspec_set.methodno%type;
v_countaql iqc_inspec_set.countaql%type;
v_methodno_jl iqc_inspec_set.measure_methodno%type;
begin
--?????????
declare cursor acc_cursor is
select y.plant,y.geadeno,y.methodno,y.measure_methodno,y.countaql
from iqc_inspec_set y
where y.plant=trim(:new.plant) and y.p_no=trim(:new.p_no);
begin
open acc_cursor;
fetch acc_cursor into v_plant,v_grade,v_methodno,v_methodno_jl,v_countaql;
close acc_cursor;
end;
--??????????
declare cursor mycursor1 is
select a.id,a.subclassno from iqc_spec a where exists
(select b.specid from iqc_inspec_execute_spec b
where b.specid=a.id and b.executeid=trim(:new.executeid));
begin
open mycursor1;
fetch mycursor1 into v_specid,v_subclassno;
while mycursor1%found
loop
--???????? AQL,????
if (v_subclassno<3) then
insert into iqc_lot_info (stutasid,subclassno,spec_id,grade_no,method_no,acc_aql,plant)
values(:new.id,v_subclassno,v_specid,v_grade,v_methodno,v_countaql,v_plant);
else
insert into iqc_lot_info (stutasid,subclassno,spec_id,method_no,plant)
values(:new.id,v_subclassno,v_specid,v_methodno_jl,v_plant);
end if;
fetch mycursor1 into v_specid,v_subclassno;
end loop;
close mycursor1;
end;
--?????????
insert into iqc_lot_info (stutasid,subclassno,spec_id,plant)
values(:new.id,0,'F590039595F758E1E030850A6382459B',v_plant);
--?????????????????
insert into iqc_check (stutasid,subclassno,spec_id)
values(:new.id,0,'F590039595F758E1E030850A6382459B');
--dbms_output.put_line(v_plant||v_grade||v_mothod||v_countaql);
end;
- 关于触发器
- 关于触发器
- 关于触发器
- 关于触发器
- 关于触发器
- 关于触发器
- 关于触发器的问题?
- 关于 INSTEAD OF 触发器
- 关于触发器的理解
- 关于触发器问题
- 关于 INSTEAD OF 触发器
- 关于触发器的纠结
- 关于SQL触发器
- 关于SQL Server触发器
- 关于触发器一些小结
- 关于ToggleMenu触发器菜单
- 关于Mysql 触发器
- 关于MSDN《了解 DML 触发器》
- C#小技巧 发现的一些不太注意的小功能
- 关键字synchronized
- postgresql_pg_hba.conf 文件
- C#强化系列文章三:实验分析C#中三种计时器使用异同点
- android的logcat详细用法
- 关于触发器
- ASP.NET读取网络图片并在页面上显示
- log4j 配置介绍
- 《实用IT项目管理(英文版.第3版)》
- C#创建快捷方式
- 2011-01-17心情
- 自己的第一个程序 — QT聊天软件 小感
- Visual.Assist.X.V10.6.1822的破解补丁,正式发行版本,推荐更新 2010.04.22 (General release.)
- 文字的陷阱