一.知识点
1.写完触发器后,要有/,再写事件。全部选中后点击运行脚本
2.删除触发器:drop trigger 触发器名字
二.题目
1.利用触发器,在星期一、周末(周六和周日)不容许更新emp数据表。
提示:星期一和周末更新emp数据表,则抛出异常RAISE_APPLICATION_ERROR(-20008,'在周末及周一不容许更新emp数据表!') ;
注意:1> 题目的这种异常,直接使用,不用定义,不用raise
2>找sysdate都需要from dual
2.涨工资,要求员工涨后的工资不能低于原来的工资,并且所涨的工资不能超过原工资的50%。
create or replace trigger zhang
before update
on emp
for each row
begin
if :new.sal > :old.sal*1.5 or :new.sal < :old.sal then
dbms_output.put_line('工资只升不降,升幅不超过50%');
end if;
end;
/
set serveroutput on
update emp set sal=sal+1000 where empno=7369;