【雪野实训记录】Oracle数据库 T8作业——触发器
题目: 一、 emp员工表(empno员工号/ename员工姓名/job工作/mgr上级编号/hiredate受雇日期/sal薪金/comm佣金/deptno部门编号) dept部门表(deptno部门编号/dname部门名称/loc地点) 1.禁止员工在休息日改变雇员信息 2.限制员工的工资不能超过当前的最高工资 3.设置员工的工资不能低于原工资,但也不能高出原工资的20% 解析:
--1.禁止员工在休息日改变雇员信息 create or replace trigger tr_sec_emp before insert or update or delete on emp begin if to_char(sysdate,'DAY','nls_date_language=AMERICAN')in('SAT','SUN') then case when inserting then raise_application_error(-20001,'不能在休息日增加雇员信息!'); when updating then raise_application_error(-20002,'不能在休息日修改雇员信息!'); when deleting then raise_application_error(-20003,'不能在休息日删除雇员信息!'); end case;end if;end; --2.限制员工的工资不能超过当前的最高工资 create or replace trigger tr_emp_salary before insert or update of sal on emp for each row declare maxSalary number(10,2); begin select max(sal) into maxSalary from emp; if :new.sal>maxSalary then raise_application_error(-20010,'员工工资超出工资上限!'); end if; end; --3.设置员工的工资不能低于原工资,但也不能高出原工资的20% create or replace trigger tr_emp_say before update of sal on emp for each row when (new.sal< old.sal or new.sal> old.sal*1.2) begin raise_application_error(-20011,'员工不能降薪,但工资升幅不能超过20%!'); end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |