一、
emp员工表(empno员工号/ename员工姓名/job工作/mgr上级编号/hiredate受雇日期/sal薪金/comm佣金/deptno部门编号)
dept部门表(deptno部门编号/dname部门名称/loc地点)
1. 禁止员工在休息日改变雇员信息
2. 限制员工的工资不能超过当前的最高工资
3. 设置员工的工资不能低于原工资,但也不能高出原工资的20%
emp员工表(empno员工号/ename员工姓名/job工作/mgr上级编号/hiredate受雇日期/sal薪金/comm佣金/deptno部门编号)
dept部门表(deptno部门编号/dname部门名称/loc地点)
1.禁止员工在休息日改变雇员信息
CREATE OR REPLACE TRIGGER TRI_EMP
BEFORE UPDATE OR DELETE OR INSERT ON EMP
FOR EACH ROW
BEGIN
IF(SYSDATE>(ROUND(sysdate,'day')+(INTERVAL '-1' DAY)) AND "SYSDATE"<(ROUND(sysdate,'day')+(INTERVAL '+1' DAY))) THEN
raise_application_error(-20000,'禁止修改雇员信息');
ELSE
dbms_output.put_line('雇员信息修改成功');
END IF;
END;
SELECT ROUND(sysdate,'day')+(INTERVAL '+2' DAY)
FROM DUAL;
UPDATE EMP
SET SAL=200
WHERE EMPNO>7369;
2.限制员工的工资不能超过当前的最高工资
CREATE OR REPLACE PACKAGE P_MSAL AS
MAXSAL NUMBER;
END;
CREATE OR REPLACE TRIGGER TRI_SAL
BEFORE UPDATE OF SAL ON EMP
FOR EACH ROW
BEGIN
SELECT "MAX"(SAL) INTO P_MSAL.MAXSAL
FROM EMP;
END;
CREATE OR REPLACE TRIGGER TRI_SAL
BEFORE UPDATE OF SAL ON EMP
FOR EACH ROW
DECLARE
BEGIN
IF(:NEW.SAL>P_MSAL.MAXSAL) THEN
raise_application_error(-20000,'职员薪金超限,拒绝服务');
ELSE
dbms_output.put_line('薪金修改成功');
END IF;
END;
3.设置员工的工资不能低于原工资,但也不能高出原工资的20%
CREATE OR REPLACE TRIGGER TRI_MSAL
BEFORE UPDATE OF SAL ON EMP
FOR EACH ROW
DECLARE
BEGIN
IF(:NEW.SAL>=:OLD.SAL AND :NEW.SAL<=:OLD.SAL*(1*0.2)) THEN
dbms_output.put_line('职员薪金修改成功');
ELSE
raise_application_error(-20000,'薪金修改失败');
END IF;
END;