在SCOTT.EMP表中创建一个触发器:
当员工的工资修改后,计算各个部门的工资总和,如果部门工资总和超过10000时,显示该部门的名称,如果部门工资超过 12000的时候,显示“有个部门工资超过界限”,否则显示“所有部门工资正常”。
加急  - - !作业中

解决方案 »

  1.   

    create or replace trigger tr_emp
      before update on emp
      for each row
    declare
      total number;
      dname dept.dname%type;
      pragma autonomous_transaction;
    begin
      select sum(sal) into total from emp where deptno = :new.deptno;
      if total > 12000 then
        select dname into dname from dept t where t.deptno = :new.deptno;
        dbms_output.put_line('部门' || dname || '的工资超过界限!');
      elsif total > 10000 then
        select dname into dname from dept t where t.deptno = :new.deptno;
        dbms_output.put_line('部门' || dname || '工资超时10000');
      else
        dbms_output.put_line('所有部门工资正常!');
      end if;
    end;
    /
      

  2.   


    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;
    /
      

  3.   


    --发这么多的帖子create or replace trigger tri_sal after update on emp for each row
    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;
      

  4.   

    create or replace trigger tri_sal after update on emp for each row
    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;
      

  5.   

    触发器里写dbms_output的意义何在 - -
      

  6.   


    估计只是为了测试测试,真要跟程序比如Java连接,还是要采用抛异常的形式,在程序中捕获,然后输出到用户界面