oracle笔记--触发器
来源:互联网 发布:百度网盘 不限速 知乎 编辑:程序博客网 时间:2024/05/16 14:15
--1. 禁止员工在休息日改变雇员信息
create or replace trigger tri_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(-20001,'不能在休息日修改雇员信息!');
when deleting then
raise_application_error(-20001,'不能在休息日删除雇员信息!');
end case;
end if;
end;
---2. 限制员工的工资不能超过当前的最高工资
create or replace trigger tri_emp_salary before update of sal on emp
for each row
declare
max_salary number;
begin
select max(sal) into max_salary from emp;
if :new.sal > max_salary then
raise_application_error(-20010,'员工工资超出工资上限!');
end if;
end;
update emp set sal = 7777 where empno = 7369
select sal from emp where empno = 7369
--3. 设置员工的工资不能低于原工资,但也不能高出原工资的20%
create or replace trigger tri_update_salary
before update of sal on emp for each row
when ( new.sal < old.sal or new.sal >old.sal*0.2)
begin
raise_application_error(-20010,'员工工资不能降薪,也不能超出工资20%!');
end;
update emp set sal = 666 where empno=7369
create or replace trigger tri_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(-20001,'不能在休息日修改雇员信息!');
when deleting then
raise_application_error(-20001,'不能在休息日删除雇员信息!');
end case;
end if;
end;
---2. 限制员工的工资不能超过当前的最高工资
create or replace trigger tri_emp_salary before update of sal on emp
for each row
declare
max_salary number;
begin
select max(sal) into max_salary from emp;
if :new.sal > max_salary then
raise_application_error(-20010,'员工工资超出工资上限!');
end if;
end;
update emp set sal = 7777 where empno = 7369
select sal from emp where empno = 7369
--3. 设置员工的工资不能低于原工资,但也不能高出原工资的20%
create or replace trigger tri_update_salary
before update of sal on emp for each row
when ( new.sal < old.sal or new.sal >old.sal*0.2)
begin
raise_application_error(-20010,'员工工资不能降薪,也不能超出工资20%!');
end;
update emp set sal = 666 where empno=7369
- oracle 笔记6 触发器
- Oracle 学习笔记 触发器
- oracle触发器使用笔记
- oracle 触发器学习笔记
- Oracle触发器学习笔记
- oracle触发器使用笔记
- Oracle 触发器笔记
- oracle 笔记触发器
- oracle笔记--触发器
- oracle 触发器 学习笔记
- oracle触发器学习笔记
- oracle-触发器笔记
- oracle学习笔记_触发器
- oracle学习笔记_触发器
- oracle学习笔记_触发器
- oracle学习笔记_触发器
- oracle学习笔记_触发器
- oracle学习笔记_触发器
- oracle笔记7--存储过程触发器
- 设计模式C++实现(11)——装饰模式
- Unable to connect to the remote server 问题
- 有向图强连通分量的Tarjan算法
- 设计模式C++实现(12)——备忘录模式
- oracle笔记--触发器
- 设计模式C++实现(13)——中介者模式
- 设计模式C++实现(14)——职责链模式
- oracle笔记--在线考试综合实例
- 英语秘籍
- Qt Model/View学习笔记之七Delegate类
- UVa 299 Train Swapping (冒泡排序的次数)
- 搜索大戏:上半场还未落幕,下半场才刚开启
- 设计模式C++实现(15)——观察者模式