给员工涨工资,要求从最低工资涨起,每个员工涨10%,且最低工资不能超过五万元。计算涨工资的员工人数和涨工资后的工资总和,且打印输出。
set serveroutput on
declare
cursor cemp is select empno,sal from emp order by sal ;
pempno emp.empno%type;
psal emp.sal%type;
countEmp number := 0;
salTotal number;
begin
select sum(sal)into salTotal from emp;
open cemp;
loop
exit when salTotal > 50000;
fetch cemp into pempno,psal;
exit when cemp%notfound;
update emp set sal=sal * 1.1 where empno=pempno;
countEmp := countEmp + 1;
salTotal := salTotal + sal * 0.1;
end loop;
close cemp;
commit;
dbms_output.put_line('涨工资的人数:'|| countEmp || ' 涨工资后的工资总额是: '|| salTotal);
end;
/
为什么执行后显示错误:错误报告 -
ORA-06550: 第 16 行, 第 24 列:
PLS-00201: 必须声明标识符 'SAL'
ORA-06550: 第 16 行, 第 1 列:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
salTotal := salTotal + sal * 0.1;
sal 改成emp.sal