set serveroutput on;
declare
cursor cur is
select hiredate, count(1) as pnum from (select to_char(hiredate, 'yyyy') hiredate from emp) group by hiredate order by hiredate;
phiredate varchar2(4);
pnum number;
ptotal number := 0;
declare
cursor cur is
select hiredate, count(1) as pnum from (select to_char(hiredate, 'yyyy') hiredate from emp) group by hiredate order by hiredate;
phiredate varchar2(4);
pnum number;
ptotal number := 0;
2016-07-13
begin
open cur;
loop
fetch cur into phiredate, pnum;
exit when cur%notfound;
ptotal := ptotal + pnum;
dbms_output.put_line(phiredate||':'||pnum);
end loop;
dbms_output.put_line('total:'||ptotal);
close cur;
end;
/
open cur;
loop
fetch cur into phiredate, pnum;
exit when cur%notfound;
ptotal := ptotal + pnum;
dbms_output.put_line(phiredate||':'||pnum);
end loop;
dbms_output.put_line('total:'||ptotal);
close cur;
end;
/
2016-07-13
set serveroutput on;
declare
cursor cur is
--select to_char(hiredate, 'yyyy') hiredate, count(1) as pnum from emp group by to_char(hiredate, 'yyyy');
select hiredate, count(1) as pnum from (select to_char(hiredate, 'yyyy') hiredate from emp) group by hiredate order by hiredate;
declare
cursor cur is
--select to_char(hiredate, 'yyyy') hiredate, count(1) as pnum from emp group by to_char(hiredate, 'yyyy');
select hiredate, count(1) as pnum from (select to_char(hiredate, 'yyyy') hiredate from emp) group by hiredate order by hiredate;
2016-07-13
phiredate varchar2(4);
pnum number;
ptotal number := 0;
begin
open cur;
loop
fetch cur into phiredate, pnum;
exit when cur%notfound;
ptotal := ptotal + pnum;
if phiredate='1980' then
dbms_output.put_line(phiredate||':'||pnum);
pnum number;
ptotal number := 0;
begin
open cur;
loop
fetch cur into phiredate, pnum;
exit when cur%notfound;
ptotal := ptotal + pnum;
if phiredate='1980' then
dbms_output.put_line(phiredate||':'||pnum);
2016-07-13
elsif phiredate='1981' then
dbms_output.put_line(phiredate||':'||pnum);
elsif phiredate='1982' then
dbms_output.put_line(phiredate||':'||pnum);
else dbms_output.put_line(phiredate||':'||pnum);
end if;
end loop;
dbms_output.put_line('total:'||ptotal);
close cur;
end;
/
dbms_output.put_line(phiredate||':'||pnum);
elsif phiredate='1982' then
dbms_output.put_line(phiredate||':'||pnum);
else dbms_output.put_line(phiredate||':'||pnum);
end if;
end loop;
dbms_output.put_line('total:'||ptotal);
close cur;
end;
/
2016-07-13