手记

啦啦啦啦员工工资合计代码

set serveroutput on; 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; totalsal number; begin open cdept; loop fetch cdept into pdeptno; exit when cdept%notfound; count1:=0;count2:=0;count3:=0;totalsal:=0; open cemp(pdeptno); loop fetch cemp into psal; exit when cemp%notfound; if psal < 3000 then count1:=count1+1; elsif psal >= 3000 and psal <= 6000 then count2:=count2+1; elsif psal > 6000 then count3:=count3+1; end if; totalsal:=totalsal+psal; end loop; insert into test values(pdeptno,count1,count2,count3,totalsal); close cemp; end loop; close cdept; dbms_output.put_line('完成'); commit; end;
2人推荐
随时随地看视频
慕课网APP