declare
--定义游标
    cursor cemp is select to_char(hiredate,'yyyy') from emp;
    phiredate varchar2(4);
    --定义每年入职的人数
    count80 number:=0;
    count81 number:=0;
    count82 number:=0;
    count87 number:=0;
    begin
      --打开光标
      open cemp;
      --循环
     loop
       --取一个员工的入职年份
       fetch  cemp into phiredate;
       --定义循环出口
        exit when cemp%notfound;
        --if判断
        if phiredate='1980' then  count80:=count80+1;
        elsif phiredate='1981' then  count81:=count81+1;
        elsif phiredate='1982' then count82:=count82+1;
        else count87:=count87+1;
        end if;

--结束循环
      end loop;
      --关闭游标
      close cemp;
      --输出
       dbms_output.put_line('total:'||(count80+count81+count82+count87));
       dbms_output.put_line('1980:'||count80);
       dbms_output.put_line('1981:'||count81);
       dbms_output.put_line('1982:'||count82);
       dbms_output.put_line('1987:'||count87);
      end;

相关文章:

  • 2022-01-11
  • 2021-11-24
  • 2022-12-23
  • 2021-09-21
  • 2021-11-14
  • 2022-12-23
  • 2021-09-19
  • 2021-12-05
猜你喜欢
  • 2022-02-13
  • 2021-12-13
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-12-10
  • 2021-08-27
相关资源
相似解决方案