PL / SQl-找到年薪总增幅

时间:2014-03-05 04:01:58

标签: mysql sql plsql

有一个没有工资和工资的员工。我需要找工资加薪,新工资和薪水总额增加。

DECLARE

CURSOR cur_emp IS
SELECT empno, sal
FROM employee
WHERE job <> 'PRESIDENT'// 
FOR UPDATE NOWAIT;
lv_cursal_num NUMBER(6);
lv_raise_num NUMBER(6);
lv_newsal_num NUMBER(6);
v_salinc_num NUMBER(6);

BEGIN

FOR rec_emp IN cur_emp LOOP
lv_cursal_num := rec_emp.sal * 12;
lv_raise_num := rec_emp.sal * 12 * .06;
lv_newsal_num := lv_cursal_num + lv_raise_num;
IF lv_raise_num > 2000 THEN
lv_raise_num := 2000;
lv_newsal_num := lv_cursal_num + lv_raise_num;

END IF;
--UPDATE employee SET sal = lv_newsal_num/12 WHERE CURRENT OF cur_emp;
Dbms_Output.put_line('Emp no: ' || rec_emp.empno ||' Current Annual Salary: ' ||             lv_cursal_num ||
' Salary Raise: ' ||lv_raise_num||' Proposed New Annual Salary: '||lv_newsal_num);
END LOOP;

END;

现在我需要增加年薪总额

我尝试使用sum(lv_newsal_num - lv_cursal_num)

请帮助

1 个答案:

答案 0 :(得分:0)

您所需要做的就是总结lv_raise_num值。

在循环开始之前,将v_salinc_num设置为0。

v_salinc_num := 0;

然后在IF条件之后将lv_raise_num值添加到v_salinc_num。

BEGIN

FOR rec_emp IN cur_emp LOOP
lv_cursal_num := rec_emp.sal * 12;
lv_raise_num := rec_emp.sal * 12 * .06;
lv_newsal_num := lv_cursal_num + lv_raise_num;
IF lv_raise_num > 2000 THEN
lv_raise_num := 2000;
lv_newsal_num := lv_cursal_num + lv_raise_num;

END IF;

v_salinc_num := v_salinc_num + lv_raise_num;

Dbms_Output.put_line('Emp no: ' || rec_emp.empno ||' Current Annual Salary: ' ||             lv_cursal_num ||
' Salary Raise: ' ||lv_raise_num||' Proposed New Annual Salary: '||lv_newsal_num);
END LOOP;

Dbms_Output.put_line('Total annual increment: ' || v_salinc_num);

一旦循环结束,v_salinc_num的年增长总额