标签:open ota ber output etc to_char arch number nbsp
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;
标签:open ota ber output etc to_char arch number nbsp
原文地址:https://www.cnblogs.com/newcityboy/p/11979896.html