--用PL/SQL语言编写一程序,实现按部门分段
--(6000以上、6000-3000,3000元以下)统计各个
--工资段的职工人数、以及各部门的工资总额(工资总额中不包括奖金)
--创建结果表--存储结果数据
create table msg
(deptno number,
count1 number,
count2 number,
count3 number,
saltotal number);
declare
--部门的光标
cursor cdept is select deptno from dept;
pdeptno dept.deptno%type;
--部门中员工的薪水
cursor cemp(dno number) is select sal from emp where deptno=dno;
psal emp.sal%type;
--每个段的员工人数
count1 number;
count2 number;
count3 number;
--每个部门的工资总额
saltotal number;
begin
--打开部门的光标
open cdept;
loop
--取出一个部门
fetch cdept into pdeptno;
exit when cdept%notfound;
--初始化的工作
count1:=0;count2:=0;count3:=0;
--得到部门的工资总额
--1、select sum(sal) into saltotal from emp where deptno=???
select sum(sal)into saltotal from emp where deptno=pdeptno;
--取部门中员工的薪水光标
open cemp(pdeptno);
loop
fetch cemp into sal;
end loop;
close cemp;
--保存当前部门的结果
insert into msg values(pdeptno,count1,count2,count3,nvl(saltotal,0));
end loop;
--关闭部门的光标
close cdept;
--提交
commit;
dmbs_output.put_line("统计完成");
end;
用PL/SQL语言编写一程序,实现按部门分段统计各个工资段的职工人数、以及各部门的工资总额
最新推荐文章于 2022-03-16 16:56:27 发布