create table std(deptno number(2),sal number(5));
insert into std values(10,2917);
insert into std values(20,2175);
insert into std values(30,1567);
create table emp1
as select * from emp;
create table emp2
as select * from emp;
我写的触发器如下:
create or replace trigger test
after insert on emp1
for each row
declare
v_sal emp1.sal%type;
begin
select sal into v_sal from std where deptno=:new.deptno;
if
:new.sal<v_sal
then
insert into emp2 values(:new.EMPNO,:new.ENAME,:new.JOB,:new.MGR,:new.HIREDATE,:new.SAL,:new.COMM,:new.DEPTNO);
end if;
update std set sal=(select avg(sal) from emp1 group by deptno having deptno=:new.deptno) where deptno=:new.deptno;
end;
测试触发器如下:
insert into emp1 values(1222,'PING','CLERK',2222,to_date('9-27-2006','MM-DD-YYYY'),1900,NULL,20)