您的位置:首页 > 其它

员工涨工资问题

2017-10-14 20:36 591 查看
/*案例

为员工涨工资。从最低工资涨起每人涨10%,但工资总额不能超过5万元,

请计算涨工资的人数和涨工资后的工资总额,并输出涨工资人数及工资总额。

*/

/*分析

SQL语句

select empno,sal from emp order by sal;

–>光标–> 循环 –> 退出条件:1.工资总额>5w 2.%notfound

变量:1.初始值 2.如何得到

涨工资的人数:

countEmp number := 0;

涨后的工资总额:

salTotal number;

1. select sum(sal) into salTotal from emp;

2.涨后的工资总额= 涨前的工资总额+ sal* 0.1

*/

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
fetch cemp into pempno, psal;
exit when cemp%notfound;

--涨后的工资总额(使用涨后的工资判断是否大于50000)
exit when salTotal + psal*0.1 >50000;
salTotal := salTotal + psal*0.1;
update emp set sal = sal*1.1 where empno = pempno;
countEmp := countEmp + 1;

end loop;

--关闭光标
close cemp;
commit;
dbms_output.put_line('涨工资的人数为:'||countEmp||',涨后的工资总额为:'||salTotal);

end;
/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐