日期:2014-05-17  浏览次数:20814 次

请解释这段触发器代码的含义?
请解释如下代码的意思,详细注解每行带码的含义,谢谢!

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_salary
instead of update

--触发器以来对象
on vw_employee_salary

begin

--声明变量totalMonth
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;

------解决方案--------------------
--创建一个触发器名字为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]