zoukankan      html  css  js  c++  java
  • 关于 if条件 光标 循环的综合应用

     用PL/SQL语言编写一个程序,实现按部门分段(6000以上,3000-6000,3000以下)统计各工资段的职工人数 和工资总额(scott--emp)

     declare
         cursor cdeptno is select deptno from dept;
         cd dept.deptno%type;
         cursor cempno(ce number) is select empno,sal from emp where deptno=cd;
         ce emp.empno%type;
         cs emp.sal%type;
         sumsal number:=0;
         count3 number:=0;
         count36 number:=0;
         count6 number:=0;
     begin
         open cdeptno;
                dbms_output.put_line('部门'||'小于3000'||'3000-6000'||'大于6000'||'sumsal');
             loop
                 fetch cdeptno into cd;
                 exit when cdeptno%notfound;
                    open cempno(cd);
                     sumsal :=0;
                     count3 :=0;
                     count36 :=0;
                     count6 :=0;
                     loop
                        fetch cempno into ce,cs;
                        exit when cempno%notfound;
                        if cs >=6000 then count6 :=count6+1;
                        elsif cs < 6000 and cs>=3000 then count36 :=count36+1;
                        elsif cs<3000 then
                         count3 :=count3+1;
                        end if;
                         sumsal :=sumsal + cs;
                     end loop;
                    close cempno;
                 dbms_output.put_line(cd||' '||count3||' '||count36||' '||count6||' '||sumsal);
             end loop;
         close cdeptno;
     end;
    /

  • 相关阅读:
    Solution -「ARC 101D」「AT4353」Robots and Exits
    Solution -「多校联训」轮回
    Solution -「多校联训」种蘑菇
    Solution -「多校联训」染色
    luoguP4389 完全背包计数
    Js 之notification浏览器桌面通知
    Linux 之shell脚本调用另一个shell脚本
    Linux 之开机自启动脚本
    Js 之简单ajax封装
    PHP 之phpsocket.io客户端主动推送给服务器
  • 原文地址:https://www.cnblogs.com/savepoint/p/5315254.html
Copyright © 2011-2022 走看看