DECLARE
- define a cursor
Cursor CEMP IS SELECT TO_CHAR (HireDate, 'YYYY') from EMP;
phiredate VARCHAR2 (. 4);
- the annual number entry defines
count80 Number: = 0;
count81 Number: = 0;
count82 Number: = 0 ;
count87 Number: = 0;
the begin
- open cursor
open CEMP;
- cyclic
loop
- taking a year employee entry
fETCH iNTO phiredate CEMP;
- defined circulation outlet
exit When CEMP% NOTFOUND;
--IF determining
if phiredate = '1980' the then count80: + = count80. 1;
ELSIF phiredate = '1981' the then count81: + = count81. 1;
ELSIF phiredate = '1982' the then count82: + = count82. 1;
the 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;