请解释如下代码的意思,详细注解每行带码的含义,谢谢!
create or replace trigger tr_update_employee_salary
instead of update
on vw_employee_salary
begin
declare totalMonth number;
begin
select count(distinct(month)) into totalMonth from t_salary where employee_id=:old.employee_id;
update t_salary set salary + (:new.total-:old.total)/totalMonth where employee_id=:old.employee_id;
end;
end;
------解决方案--------------------
- SQL code
--create or replace trigger起至end ,一套语法结构,创建一个触发器(create or replace触发下面的代码)create or replace trigger tr_update_employee_salaryinstead of update--触发器以来对象on vw_employee_salarybegin--声明变量totalMonthdeclare totalMonth number;begin--给变量赋值select count(distinct(month)) into totalMonth from t_salary where employee_id=:old.employee_id;--更新到另外一张表update t_salary set salary + (:new.total-:old.total)/totalMonth where employee_id=:old.employee_id;end;end;
------解决方案--------------------
--创建一个触发器名字为tr_update_employee_salary, create or replace trigger是固定创建触发器的语句
create or replace trigger tr_update_employee_salary
instead of update --这句是有更新的时候就会触发
on vw_employee_salary ]--这句是在vw_employee_salary这个对象进行触发
begin --开始执行的语句
declare totalMonth number; --声明变量为totalMonth number
begin --开始执行的语句
--给变量赋值
select count(distinct(month)) into totalMonth from t_salary where employee_id=:old.employee_id;
--更新到另外一张表
update t_salary set salary + (:new.total-:old.total)/totalMonth where employee_id=:old.employee_id;
end;
end;
[/Quote]