plsql实现统计员工入职年份人数

--统计公司员工入职年份的员工数
 
   declare
    cursor  p_cursor  is select to_char(hiredate,'YYYY' ) from emp;
    p_hiredate char(10);
    count80 number:=0;
    count81 number:=0;
    count87 number:=0;
    count82 number:=0;
   begin
   open p_cursor;
   loop
     fetch  p_cursor into  p_hiredate;
     exit when  p_cursor%notfound;
    
     if p_hiredate='1980' then count80:=count80+1;
     elsif p_hiredate='1981' then count81:=count81+1;
     elsif p_hiredate='1987' then count87:=count87+1;
   
     else  count82:=count82+1;
     end if;
   end loop;
  
   close  p_cursor;
  
     dbms_output.put_line(count80);
     dbms_output.put_line(count81);
     dbms_output.put_line(count87);
     dbms_output.put_line(count82);
   end;

猜你喜欢

转载自apple578994358gg.iteye.com/blog/2086298