《oracel触发器》由会员分享,可在线阅读,更多相关《oracel触发器(5页珍藏版)》请在金锄头文库上搜索。
1、1. 在 emp 表上创建一个触发器,保证每天 8:00-17:00 之外的时间禁止对该表进行 DML 操作。create or replace trigger tr_emp_workbefore insert or update or delete on empdeclarea varchar2(50);n number;beginselect to_char(sysdate,hh24) into n from dual;if n17 thenraise_application_error(-20002,禁止在八点前五点后修改数据);end if;end;2.在 emp 表上创建一个触发器,
2、当插入、删除或修改员工信息时,统计各个部门的人数及平均工资,并输出。CREATE OR REPLACE TRIGGER trg_empAFTER INSERT OR UPDATE OR DELETE ON EMPDECLAREv_sal emp.sal%type;v_count number;BEGINSELECT AVG(SAL),COUNT(*) INTO V_SAL,V_COUNT FROM EMP;DBMS_OUTPUT.PUT_LINE(V_SAL| |V_COUNT);END;3.在 emp 表上创建一个触发器,保证修改员工工资时,修改后的低于该部门最高工资,同时高于该部门最低工资
3、。create or replace trigger pk_emp before insert or update on emp for each rowdeclarev_max number(6);v_min number(6);beginselect max(sal) into v_max from emp ;select min(sal) into v_min from emp;if :new.sal v_max and :new.sal v_max and :new.sal v_highsal or pkg_deptno.v_salv_lowsal THENRAISE_APPLICATION_ERROR(-20001,THE SAL IS BEYOND!);END IF;END;