`
ghyghoo8
  • 浏览: 190747 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

院校招生情况统计 COLLEGE_TOTAL

阅读更多
create or replace procedure COLLEGE_TOTAL is
--定义一个记录
type t_AuthRec is record(
               coid number,  
               avgscorce number,
                maxscorce number,  
               minscorce number,  
                totalnum number,  
                 boynum number, 
                  girlnum number
            );
--定义记录表下标索引
  i binary_integer := -1 ;
  --定义记录表类型
  type tmp_table_type is table of t_AuthRec index by binary_integer ;
  --定义记录表变量
  v_tmp_table tmp_table_type ;
--decode分支函数,常用于count()的统计判断cursor v_college_list is select c.collegeid,avg(ts.totalsco),max(ts.totalsco),min(ts.totalsco),c.actual_total,count(decode(sex,0,sex,1,null)) boy,c.actual_total -count(decode(sex,0,sex,1,null)) girl
from college c,mat m,student s,totalscore ts where c.collegeid=m.mat_collegeid and s.stuid=m.stuid  and ts.stuid=s.stuid
group by c.collegeid ,c.actual_total


[size=small]--使用avg,max,min,count等统计函数时,必须要有gounp by,否则无法正常输出!!
[/size]
----------------------------------------------------------------------
order by avg(ts.totalsco) desc;

begin
  --给记录表变量赋值
  for v_record in v_college_list loop
  v_tmp_table(i) :=v_record  ;
  i := i + 1 ;
  end loop;
 
  --输出记录表变量的值
  for j in v_tmp_table.first..v_tmp_table.last loop
--记录表,输出自定义类型的变量名v_tmp_table(j).coid!!!
   Dbms_Output.put_line('院校编号:'||v_tmp_table(j).coid);
    Dbms_Output.put_line('平均分数:'||v_tmp_table(j).avgscorce);
   Dbms_Output.put_line('最大分数:'||v_tmp_table(j).maxscorce);
   Dbms_Output.put_line('最小分数:'||v_tmp_table(j).minscorce);
   Dbms_Output.put_line('录取总人数:'||v_tmp_table(j).totalnum);
   Dbms_Output.put_line('男人数:'||v_tmp_table(j).boynum);
   Dbms_Output.put_line('女人数:'||v_tmp_table(j).girlnum);
  end loop;



end COLLEGE_TOTAL;

--过程名和参数:COLLEGE_TOTAL
--功能:按照院校的平均录取分数排序所有院校,统计各院校的最高分数、
--最低分数,招生人数、录取人数、男生人数、女生人数等信息。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics