Oracle显示根据高考分数模拟录取
数据库  /  管理员 发布于 3年前   270
题目要求:
1,创建student表和result表2,pl/sql对学生的成绩数据进行处理3,处理的逻辑是根据每门专业课的最低分线和总分的最低分数线自动的将录取和落选
1,创建student表,和result表
学生信息表;
create table student( student_id number primary key,--学生id math number,--数学分数 chinaese number,--语文分数 en number,--英语分数 wenke number,--文科学分 likenumber number,--理科分数 zhuanyeke number,--专业分数 student_sum number --总分);
学生录取状态表;
create table result( student_id number, enrollresult number );
2.插入一些考生的数据
student表插入数据;
理科insert into student(student_id,math,chinaese,en,likenumber,STUDNET_SUM) values(4307211993,120,130,140,260,650);insert into student(student_id,math,chinaese,en,likenumber,STUDNET_SUM) values(4307211997,20,30,40,260,350);insert into student(student_id,math,chinaese,en,likenumber,STUDNET_SUM) values(4307211998,120,30,240,130,520);理科专业insert into student(student_id,math,chinaese,en,likenumber,zhuanyeke,STUDNET_SUM) values(4307211994,128,128,138,260,200,844);insert into student(student_id,math,chinaese,en,likenumber,zhuanyeke,STUDNET_SUM) values(4307211999,120,30,40,130,180,500);insert into student(student_id,math,chinaese,en,likenumber,zhuanyeke,STUDNET_SUM) values(4307211100,20,30,13,157,180,400);文科insert into student(student_id,math,chinaese,en,wenke,STUDNET_SUM) values(4307211995,110,140,50,270,550);insert into student(student_id,math,chinaese,en,wenke,STUDNET_SUM) values(4307211101,90,80,50,180,400);insert into student(student_id,math,chinaese,en,wenke,STUDNET_SUM) values(4307211102,110,120,80,230,540);文科专业insert into student(student_id,math,chinaese,en,wenke,zhuanyeke,STUDNET_SUM) values(4307211996,120,30,40,160,180,530);
result表插入数据;
insert into result values(4307211993);insert into rasult values(4307211997);insert into rasult values(4307211998);insert into rasult values(4307211994);insert into rasult values(4307211999);insert into rasult values(4307211100);
3,编写带参数的存储过程,记录考生的分数以及保存考生的录取状态 0表示落选,1表示录取
create or replace procedure pro_score(v_id number) isv_student_id student.student_id%type;v_math student.math%type;v_chinaese student.chinaese%type;v_en student.en%type;v_wenke student.wenke%type;v_like student.likenumber%type;v_zhuanye student.zhuanyeke%type; v_score number(7);begin select STUDENT_ID, MATH ,CHINAESE,EN ,WENKE ,LIKENUMBER ,ZHUANYEKE into v_student_id , v_math,v_chinaese,v_en ,v_wenke,v_like,v_zhuanye from student where student_id=v_id; v_score := v_math + v_chinaese + v_en + v_wenke + v_like + v_zhuanye; dbms_output.put_line('总分'||v_score); if v_score>500 then update result set ENROLLRESULT=1 where STUDENT_ID=v_id; dbms_output.put_line(v_student_id||'被录取了'); else update result set ENROLLRESULT=0 where STUDENT_ID=v_id; dbms_output.put_line(v_student_id||'落榜了'); end if;end;
4,创建游标,用于从student表中查询数据,并加入一个异常机制 0表示落选,1表示录取
set serveroutput on;create or replace procedure pro_score is myrow student%rowtype; v_score number(7); type type_cursor is ref cursor; rowcursor type_cursor ;begin open rowcursor for select * from student; loop fetch rowcursor into myrow ; v_score := myrow.math + myrow.chinaese + myrow.en + nvl(myrow.wenke,0) + nvl(myrow.likenumber,0) +nvl( myrow.zhuanyeke,0); dbms_output.put_line('总分'||v_score); exit when rowcursor%notfound; if v_score>500 then update result set ENROLLRESULT=1 where STUDENT_ID=myrow.student_id; dbms_output.put_line(myrow.student_id||'被录取了'); else update result set ENROLLRESULT=0 where STUDENT_ID=myrow.student_id; dbms_output.put_line(myrow.student_id||'落榜了'); end if;end loop;end;/
exec pro_score;
总分650
4307211993被录取了
总分350
4307211997落榜了
总分520
4307211998被录取了
总分854
4307211994被录取了
总分500
4307211999落榜了
总分400
4307211100落榜了
总分570
4307211995被录取了
总分400
4307211101落榜了
总分540
4307211102被录取了
总分530
4307211996被录取了
总分530
在游标中添加异常机制,实在是不知道怎么添加了,所以把代码和思路贴出来让大家帮我看一下;怎么解决这个问题
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号