Insert/Update 在 emp_sal_history table 中的旧工资值的包,只要工资在没有触发的情况下发生变化

Package for Insert/Update old salary value in emp_sal_history table whenever salary get changed without trigger

这是我的函数

create or replace
function sal_incr
(
p_grade number)
return number
is
v_inc number;
begin
select raise_percent into v_inc from sal_inc where grade_id = p_grade;
return  1 + (v_inc/100);
end;

这是我的程序:

create or replace 
procedure sal_increm 
is
begin
UPDATE emp_task SET sal = sal * sal_incr(grade_id);
end;

如何执行该程序包.. 不使用触发器如何在单独的 table

中更新 "old sal"、"modified by" 和 "modified on"

您可以在一个过程中有多个 DML 语句;如果你不能,它们就没有那么有用了。您可以根据任务 table 中的数据对您的历史记录 table 进行一次插入,然后使用 the USER function and and the current time with SYSDATE.

添加执行用户
create or replace 
procedure sal_increm 
is
begin
  insert into emp_sal_history (empno, old_sal, modified_by, modified_on)
  select empno, sal, user, sysdate
  from emp_task;

  update emp_task set sal = sal * sal_incr(grade_id);
end;
/

如果你也想记录新工资,你也可以在插入中计算。

这将记录一个历史记录,即使是那些成绩没有得到提升的员工。如果你有这些或者想处理这种可能性并排除它们,你可以添加

where sal_incr(grade_id) != 1

您也可以将其添加到更新中。