在SCOTT.EMP表中创建一个触发器:
当员工的工资修改后,计算各个部门的工资总和,如果部门工资总和超过10000时,显示该部门的名称,如果部门工资超过 12000的时候,显示“有个部门工资超过界限”,否则显示“所有部门工资正常”。
加急 - - !作业中
当员工的工资修改后,计算各个部门的工资总和,如果部门工资总和超过10000时,显示该部门的名称,如果部门工资超过 12000的时候,显示“有个部门工资超过界限”,否则显示“所有部门工资正常”。
加急 - - !作业中
调试欢乐多
--咋发那么多?
create or replace trigger tr_emp
after update on emp
for each row
declare
total number;
pragma autonomous_transaction;
begin
select sum(sal) into total from emp where deptno = :new.deptno;
if total > 12000 then
dbms_output.put_line('部门' || :new.deptno || '的工资超过界限!');
elsif total > 10000 then
dbms_output.put_line('部门' || :new.deptno || '工资超时10000');
else
dbms_output.put_line('所有部门工资正常!');
end if;
end;
/
declare
saltxt varchar2(100);
pragma autonomous_transaction;
begin
select case
when (sum(sal)-10000)>=0 then max(:new.deptname)
when when (sum(sal)-12000)>=0 then '有个部门工资超过界限'
else '正常' end into saltxt
from emp where deptno=:new.deptno;
dbms_output.put_line(saltxt);
commit;
end;
declare
saltxt varchar2(100);
pragma autonomous_transaction;
begin
select case
when (sum(sal)-10000)>=0 then max(:new.deptno)
when when (sum(sal)-12000)>=0 then '有个部门工资超过界限'
else '正常' end into saltxt
from emp where deptno=:new.deptno;
dbms_output.put_line(saltxt);
commit;
end;
after update on emp
for each row
declare
total number;
pragma autonomous_transaction;
begin
select sum(sal) into total from emp where deptno=:new.deptno;
if total>12000 then
dbms_output.put_line('部门'||:new.deptno||'工资超过界限');
elsif total>10000 then
dbms_output.put_line('部门'||:new.deptno||'工资超过10000');
else
dbms_output.put_line('部门'||:new.deptno||'工资正常');
end if;
end;