--绩点排名--创建临时表createglobaltemporarytable temp_rank(pname VARCHAR2(20),get_GPA float)oncommitdeleterows;--存储过程show_rankcreateorreplaceprocedure show_rank
ascursor per_cursor isselect pname,get_GPA from temp_rank where get_GPA isnotnullorderby get_GPA desc;
cur per_cursor%rowtype;beginfor cur in per_cursor loop
DBMS_OUTPUT.put_line('名字--'||cur.pname||' 绩点--'||cur.get_GPA);endloop;execute immediate 'truncate table temp_rank';end;--存储过程queryPer_GPA_for_rankcreateorreplaceprocedure queryPer_GPA_for_rank(pno in Student.Sno%type,pname out Student.Sname%type,get_GPA outfloat)ascursor per_cursor isselectdistinct course.cname,curriculum.grade,course.ccredit,student.sname from curriculum,course,student where curriculum.sno=pno and course.cno=curriculum.cno and student.sno=pno;
ans float :=0;
result0 float :=0;
zongGPA float :=0;
tempGPA float :=0;
flag boolean:=true;beginfor cur in per_cursor loopexitwhen per_cursor%notfound;
zongGPA:=zongGPA+cur.ccredit;if cur.grade isnullthenbegin zongGPA:=zongGPA-cur.ccredit;end;
elsif (cur.grade between0and59)thenbegin ans:=ans+0;tempGPA:=0;end;
elsif (cur.grade between61and63)thenbegin ans:=ans+1.3*cur.ccredit;tempGPA:=1.3;end;
elsif (cur.grade between64and64)thenbegin ans:=ans+1.5*cur.ccredit;tempGPA:=1.5;end;
elsif (cur.grade between65and67)thenbegin ans:=ans+1.7*cur.ccredit;tempGPA:=1.7;end;
elsif (cur.grade between68and71)thenbegin ans:=ans+2*cur.ccredit; tempGPA:=2;end;
elsif (cur.grade between72and74)thenbegin ans:=ans+2.3*cur.ccredit;tempGPA:=2.3;end;
elsif (cur.grade between75and77)thenbegin ans:=ans+2.7*cur.ccredit;tempGPA:=2.7;end;
elsif (cur.grade between78and81)thenbegin ans:=ans+3*cur.ccredit; tempGPA:=3;end;
elsif (cur.grade between82and84)thenbegin ans:=ans+3.3*cur.ccredit;tempGPA:=3.3;end;
elsif (cur.grade between85and89)thenbegin ans:=ans+3.7*cur.ccredit;tempGPA:=3.7;end;
elsif (cur.grade between90and94)thenbegin ans:=ans+4*cur.ccredit; tempGPA:=4;end;
elsif (cur.grade between95and100)thenbegin ans:=ans+4.3*cur.ccredit;tempGPA:=4.3;end;endif;if flag thenbegin-- DBMS_OUTPUT.put_line('姓名'||cur.sname);
pname:=cur.sname;
flag:=false;end;endif;endloop;if zongGPA=0then
get_GPA :=null;else-- DBMS_OUTPUT.put_line('总绩点为--'||round(ans/zongGPA,4));
get_GPA :=round(ans/zongGPA,4);endif;end;--存储过程GPA_rankcreateorreplaceprocedure GPA_rank
ascursor per_cursor isselectdistinct sno from curriculum;
cur per_cursor%rowtype;
get_GPA_0 float;
pname_0 Student.Sname%type;beginfor cur in per_cursor loop
queryPer_GPA_for_rank(cur.sno,pname_0,get_GPA_0);insertinto temp_rank(pname,get_GPA)values(pname_0,get_GPA_0);endloop;
show_rank();end;--调用call GPA_rank();
createprocedure course_scheduling(p2 in course.cname%type,p3 in course.ccredit%type,p4 in course.type%type)as
p11 course.cno%type;beginselectmax(cno)+1into p11 from course ;insertinto course(cno, cname, ccredit,TYPE)VALUES(p11,p2,p3,p4);
DBMS_OUTPUT.put_line('插入成功');end;
createprocedure optional_course(p1 in curriculum.sno%type,p2 in curriculum.cno%type)ascursor per_cursor isselectdistinct teach.week, teach.day,teach.time,course.typefrom teach,course where teach.cno=p2 and teach.cno=course.cno and course.typelike'%选修%';
cur per_cursor%rowtype;cursor com_cursor isselectdistinct week,day,timefrom curriculum where sno=p1;
com com_cursor%rowtype;beginfor cur in per_cursor loopexitwhen per_cursor%notfound;
DBMS_OUTPUT.put_line(cur.week||cur.day||cur.time);for com in com_cursor loopexitwhen com_cursor%notfound;if cur.time=com.timeand cur.day=com.dayand cur.week=com.week then
raise_application_error(-20005,'时间冲突,不可选!');endif;endloop;endloop;for cur in per_cursor loopexitwhen per_cursor%notfound;insertinto curriculum(sno, cno, week,day,time)values(p1,p2,cur.week,cur.day,cur.time);endloop;end;
createprocedure queryclass_sche(pno in Student.classname%type)ascursor per_cursor isselect course.cname,curriculum.day,curriculum.time,curriculum.week from curriculum,student,course
where student.classname=pno and course.typein('通识类必修课程','专业必修课程')and curriculum.cno=course.cno;-- select course.cname,curriculum.day,curriculum.time,curriculum.week from curriculum,student,course-- where student.sno=curriculum.sno and trim(student.classname) <> trim(pno) and curriculum.type in('通识类必修课程','专业必修课程') and curriculum.cno=course.cno;
cur per_cursor%rowtype;begin
DBMS_OUTPUT.put_line('pno:'||pno);--DBMS_OUTPUT.put_line('课程:'||cur.cname||' 星期:'||cur.day||' 节次:'||cur.time||' 上课周数:'||cur.week);for cur in per_cursor loop-- exit when per_cursor%notfound;
DBMS_OUTPUT.put_line('课程:'||cur.cname||' 星期:'||cur.day||' 节次:'||cur.time||' 上课周数:'||cur.week);exitwhen per_cursor%notfound;endloop;end;
createprocedure queryPer_Grade(pno in Student.Sno%type)ascursor per_cursor isselectdistinct cname,grade from course,curriculum where sno=pno and curriculum.cno=course.cno;
cur per_cursor%rowtype;-- open per_cursor;begin-- open per_cursor;for cur in per_cursor loopexitwhen per_cursor%notfound;--成绩为空取零--DBMS_OUTPUT.put_line('科目--'||cur.cname||' 成绩--'||nvl(cur.grade,0));--成绩为空不操作
DBMS_OUTPUT.put_line('科目--'||cur.cname||' 成绩--'||cur.grade);--成绩为空替换为‘未录入’,还没想到endloop;-- close per_cursor;end;/
createprocedure queryPer_Sche(pno in Student.Sno%type)ascursor per_cursor isselect*from curriculum where sno=pno;
cur per_cursor%rowtype;beginfor cur in per_cursor loopexitwhen per_cursor%notfound;
DBMS_OUTPUT.put_line('数据是:'||'学号--'||cur.sno||'班号--'||cur.cno||'day--'||cur.day||'type--'||cur.type||'grade--'||cur.grade||'time--'||cur.time||'week--'||cur.week);endloop;end;/
createprocedure querystu_info(p1 in teach.tno%type,p2 in teach.cno%type)ascursor per_cursor isselectdistinct curriculum.sno,sname from curriculum,teach,student
where teach.tno=p1 and teach.cno=p2 and curriculum.cno=teach.cno and curriculum.sno=student.sno;-- and curriculum.day=teach.day and curriculum.week=teach.week and curriculum.time=teach.time;
cur per_cursor%rowtype;beginfor cur in per_cursor loopexitwhen per_cursor%notfound;
DBMS_OUTPUT.put_line('上课学生学号:'||cur.sno||' 学生姓名:'||cur.sname);endloop;end;/
createprocedure queryteacher_sche(pno in teacher.tno%type)ascursor per_cursor isselect*from teach where tno=pno;
cur per_cursor%rowtype;beginfor cur in per_cursor loopexitwhen per_cursor%notfound;
DBMS_OUTPUT.put_line('教工号:'||cur.tno||' 星期:'||cur.day||' 节次:'||cur.time||' 周数:'||cur.week);endloop;end;/
createprocedure record(p1 in teach.cno%type,p2 in curriculum.sno%type,p3 in curriculum.grade%type)as
grade1 curriculum.grade%type :=0;
cname1 course.cname%type :=null;
sname1 student.sname%type :=null;beginselectdistinct student.sname,course.cname,curriculum.grade into sname1,cname1,grade1
from student,curriculum,teach,course where teach.cno=p1
and curriculum.sno=p2
and curriculum.sno=student.sno
and teach.cno=curriculum.cno
and curriculum.cno=course.cno;
DBMS_OUTPUT.put_line(' 学生名字: '||sname1||' 课程:'||cname1);
DBMS_OUTPUT.put_line(' 原成绩:'||grade1);update curriculum set grade=p3 where sno=p2 and cno =p1;
DBMS_OUTPUT.put_line(' 现成绩:'||p3);end;/