ANDY:不是华仔,而是我。因为华仔是我的偶像,所以取名叫ANDY,希望大家多提意见!
您的消息:
|
| Su | Mo | Tu | We | Th | Fr | Sa |
|---|
| 30 | 1 | 2 | 3 | 4 | 5 | 6 |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | 1 | 2 | 3 |
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
1。触发器不能从触发器所对应的基表中读取数据;
2。create or replace trigger TR_INV
after update of ZPRICE on INV for each row
begin
if :old.ZPRICE>:new.ZPRICE then
raise_application_error(-20001,''工资只涨不降'');
end if;
end;
3。instead-of 触发器用于在复杂视图上设置触发器
1)。必须指定 for each row;
2)。只适用视图;
3)。不能有 before /after;
4)。视图不能指定 with check option;
5)。demo:
view:
create or replace view V_EMP_DEPT
as
select
E.ZEMP_ID,
E.ZDESC ZEMP_DESC,
D.ZDEPT_ID,
D.ZDESC ZDEPT_DESC
from EMP E
left join DEPT D on D.ZDEPT_ID=E.ZDEPT_ID;
trigger:
create or replace trigger TR_EMP_DEPD
instead of insert on V_EMP_DEPT for each row
declare
DEPT_COUNT int;
begin
select count(*) into DEPT_COUNT from DEPT where ZDEPT_ID=:new.ZDEPT_ID
if DEPT_COUNT=0 then
insert into DEPT values(:new.ZEMP_ID,:new.ZDEPT_ID,:new.ZDEPT_DESC);
end if;
select count(*) into DEPT_COUNT from EMP where ZEMP_ID=:new.ZEMP_ID
if DEPT_COUNT=0 then
insert into EMP values(:new.ZEMP_ID,:new.ZEMP_DESC,:new.ZDEPT_ID);
end if;
end;
4。重新编译触发器:当alter table 了以后,需要重新编译一次该表上的触发器:
alter trigger TR_EMP compile;
作者:hongyefei 阅读()
评论() 编辑 发表于:2006-06-06 15:56