如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
在emp表上创建一个触发器,保证每天8:00-17:00之外的时间禁止对该表进行DML操作。createorreplacetriggertr_emp_workbeforeinsertorupdateordeleteonempdeclareavarchar2(50);nnumber;beginselectto_char(sysdate,'hh24')intonfromdual;ifn<8orn>17thenraise_application_error(-20002,'禁止在八点前五点后修改数据');endif;end;2.在emp表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资,并输出。CREATEORREPLACETRIGGERtrg_empAFTERINSERTORUPDATEORDELETEONEMPDECLAREv_salemp.sal%type;v_countnumber;BEGINSELECTAVG(SAL),COUNT(*)INTOV_SAL,V_COUNTFROMEMP;DBMS_OUTPUT.PUT_LINE(V_SAL||''||V_COUNT);END;3.在emp表上创建一个触发器,保证修改员工工资时,修改后的低于该部门最高工资,同时高于该部门最低工资。createorreplacetriggerpk_empbeforeinsertorupdateonempforeachrowdeclarev_maxnumber(6);v_minnumber(6);beginselectmax(sal)intov_maxfromemp;selectmin(sal)intov_minfromemp;if:new.sal>v_maxand:new.sal<=v_minthenraise_application_error(-20001,'不能插入');endif;end;createorreplacetriggerpk_empbeforeinsertorupdateonempforeachrowdeclarev_maxnumber(6);v_minnumber(6);beginselectmax(sal)intov_maxfromempwheredeptno=(selectdeptnofromempwhereempno=&x);selectmin(sal)intov_minfromemp=(selectdeptnofromempwhereempno=&x);if:new.sal>v_maxand:new.sal<=v_minthenraise_application_error(-20001,'不能插入');endif;end;CREATEORREPLACEPACKAGEPKG_DEPTNOASV_DEPTNOEMP.DEPTNO%TYPE;V_SALEMP.SAL%TYPE;END;CREATEORREPLACETRIGGERtrg_updateempBEFOREUPDATEONEMPFOREACHROWBEGINPKG_DEPTNO.V_SAL:=:NEW.SAL;PKG_DEPTNO.V_DEPTNO:=:NEW.DEPTNO;END;CREATEORREPLACETRIGGERtrg_statementAFTERUPDATEONEMPDECLAREv_highsalemp.sal%type;v_lowsalemp.sal%type;BEGINSELECTMAX(SAL),MIN(SAL)INTOv_highsal,v_lowsalFROMEMPWHEREDEPTNO=PKG_DEPTNO.V_DEPTNO;IFPKG_DEPTNO.V_SAL>v_highsalorpkg_deptno.v_sal<v_lowsalTHENRAISE_APPLICATION_ERROR(-20001,'THESALISBEYOND!');ENDIF;END;