1.建立表学生信息表(stu_info)并插入数据
- create table stu_info (
- stu_num number(10) primary key,
- stu_name varchar2(10) not null,
- stu_sex varchar2(2) check(stu_sex in('M','F')),
- phone_num number(11),
- idcard_num varchar2(18),
- stu_school varchar2(50),
- post_addr varchar2(50)
- );
- insert into stu_info values (2012100201,'zs','M',13800138000,'130822198804070011','HBSJZDYZX','HBSJZSZXLWWJ47H');
- insert into stu_info values (2012100202,'ls','M',13821138012,'130822198401170051','HBSJZDYZX','HBSJZSZXLNJ143H');
- insert into stu_info values (2012100203,'ml','F',13315819091,'131812198811031004','HBSJZDYZX','HBSJZSKML33H');
- insert into stu_info values (2012100204,'ww','M',18010078102,'131822198904173312','HBCDDYZX','HBSJCDSTLJ42H');
- insert into stu_info values (2012100205,'yb','M',13511313105,'130825198704143301','HBCDDYZX','HBCDDYZX');
- insert into stu_info values (2012100206,'ff','F',18710013306,'100012198802041724','HBCDCYZX','HBCDLHRXNJ270H');
- insert into stu_info values (2012100207,'zx','F',13101108892,'130824198711122212','HBCDCYZX','HBCDLHXDZC009H');
- insert into stu_info values (2012100208,'tz','M',13800138010,'130822198804270121','HBCDLHDYZX','HBCDLHXBZC191H');
- insert into stu_info values (2012100209,'xf','M',18710081213,'13224219860612913X','HBCDLHDYZX','HBCDLHDYZX');
- insert into stu_info values (2012100210,'aq','F',13800138001,'130822198402110134','HBCDLHDYZX','HBCDLHDYZX');
- insert into stu_info values (2012100211,'lm','F',13800138100,'211800198805313114','HBCDLHDYZX','BJSXCQZLGL134H');
- insert into stu_info values (2012100212,'lw','M',18113081412,'130998198608093919','HBCDCYZX','BJSXCQZLGL134H');
- insert into stu_info values (2012211101,'bk','M',18133065974,'701822198706090115','HBSJZDYZX','HBSJZDYZX');
- insert into stu_info values (2012211102,'by','M',13900139001,'12932119880407091X','HBSJZDYZX','HBSJZSZXLWWJ90H');
- insert into stu_info values (2012211103,'mm','F',13800138041,'900838198612011136','HBSJZDYZX','HBSJZDYZX');
- insert into stu_info values (2012211104,'wj','M',13611829910,'887990198711871117','HBCDDYZX','HBCDDYZX');
- insert into stu_info values (2012211105,'jf','F',17988011992,'130826198701171008','HBSCDDYZX','HBCDDYZX');
- insert into stu_info values (2012211106,'sf','F',18890988138,'130822198804070012','HBSCDDYZX','HBSCDSGYL110H');
- insert into stu_info values (2012211107,'st','M',17799088897,'187908198811070013','HBSCDLHDYZX','HBSCDSLHZXL998H');
- insert into stu_info values (2012211108,'zd','M',13800981786,'299822198804071021','HBSCDLHDYZX','HBSCDLHDYZX');
- insert into stu_info values (2012211109,'xx','F',18900000909,'131825198709221414','HBSLHDYZX','HBSLHDYZX');
- insert into stu_info values (2012311110,'ll','M',13800090099,'13081819851009','HBSLHDYZX','HBSLHDYZX');
- insert into stu_info values (2012341401,'sq','M',18010179986,'19787619890922000X','HBSJZDYZX','HBSJZSZXLDXJ10H');
- insert into stu_info values (2012341402,'wm','F',13800138000,'131822198804070012','HBSJZDYZX','HBSJZSZXLFZL99H');
- insert into stu_info values (2012341403,'sl','M',13800198010,'198898198606091785','HBSCDDYZX','HBSCDSFPL78H');
- insert into stu_info values (2012341404,'zq','M',16310137108,'316611198801173309','HBSCDDYZX','HBSCDDYZX');
- insert into stu_info values (2012341405,'sz','F',13010013875,'101775198712041124','HBSLHDYZX','HBSLHDYZX');
- insert into stu_info values (2012341406,'bf','M',13810131100,'130822198604071701','HBSJZDYZX','HBSLHXFYL8H');
- insert into stu_info values (2012341407,'zh','F',19999999999,'99999919890929999Y','HBSLHDYZX','HBSLHDYZX');
2.建立学生志愿表(stu_wish)
- create table stu_wish (
- stu_num number(10) primary key,
- fir_university_id number(5) not null,
- sec_university_id number(5)
- );
- insert into stu_wish values (2012100201,10001,20002);
- insert into stu_wish values (2012100202,10003,20002);
- insert into stu_wish values (2012100203,10004,20001);
- insert into stu_wish values (2012100204,10004,20005);
- insert into stu_wish values (2012100205,10005,20001);
- insert into stu_wish values (2012100206,10002,20005);
- insert into stu_wish values (2012100207,10003,20003);
- insert into stu_wish values (2012100208,10001,20004);
- insert into stu_wish values (2012100209,10002,20004);
- insert into stu_wish values (2012100210,10005,20002);
- insert into stu_wish values (2012100211,10002,20003);
- insert into stu_wish values (2012100212,10003,20002);
- insert into stu_wish values (2012211101,10011,20011);
- insert into stu_wish values (2012211102,10012,20015);
- insert into stu_wish values (2012211103,10014,20014);
- insert into stu_wish values (2012211104,10013,20015);
- insert into stu_wish values (2012211105,10013,20012);
- insert into stu_wish values (2012211106,10015,20013);
- insert into stu_wish values (2012211107,10011,20012);
- insert into stu_wish values (2012211108,10012,20011);
- insert into stu_wish values (2012211109,10012,20014);
- insert into stu_wish values (2012311110,10014,20015);
- insert into stu_wish(stu_num,fir_university_id) values (2012341401,10021);
- insert into stu_wish(stu_num,fir_university_id) values (2012341402,10022);
- insert into stu_wish(stu_num,fir_university_id) values (2012341403,10023);
- insert into stu_wish(stu_num,fir_university_id) values (2012341404,10032);
- insert into stu_wish(stu_num,fir_university_id) values (2012341405,10032);
- insert into stu_wish(stu_num,fir_university_id) values (2012341406,10031);
- insert into stu_wish(stu_num,fir_university_id) values (2012341407,10033);
3.建立大学信息表(university_info)
- create table university_info (
- uni_id number(5) primary key,
- uni_name varchar2(10) not null,
- batch_id number(5),
- low_cri number(4,1));
- insert into university_info values(10001,'TsingHua',1001,632);
- insert into university_info values(10002,'BeijingUni',1001,629);
- insert into university_info values(10003,'Fudan',1001,600);
- insert into university_info values(10004,'HaGongDa',1001,601);
- insert into university_info values(10005,'BeijingLG',1001,590);
- insert into university_info values(20001,'YanShan',1002,519);
- insert into university_info values(20002,'HBFarmUni',1002,431);
- insert into university_info values(20003,'YNDX',1002,497);
- insert into university_info values(20004,'BFXY',1002,561);
- insert into university_info values(20005,'TSWL',1002,500);
- insert into university_info values(10011,'TsingHua',1003,623);
- insert into university_info values(10012,'BeijingUni',1003,617);
- insert into university_info values(10013,'Fudan',1003,585);
- insert into university_info values(10014,'ZhejiangUn',1003,601);
- insert into university_info values(10015,'BeijingRA',1003,580);
- insert into university_info values(20011,'YanShan',1004,519);
- insert into university_info values(20012,'HBFarmUni',1004,431);
- insert into university_info values(20013,'YNDX',1004,497);
- insert into university_info values(20014,'BFXY',1004,561);
- insert into university_info values(20015,'TSWL',1004,500);
- insert into university_info values(10021,'YanShan',1005,420);
- insert into university_info values(10022,'HBFarmUni',1005,431);
- insert into university_info values(10023,'TsingHua',1005,527);
- insert into university_info values(10031,'YanShan',1006,330);
- insert into university_info values(10032,'HBFarmUni',1006,359);
- insert into university_info values(10033,'TsingHua',1006,575);
4. 建立学生考试成绩表(stu_grade)
- create table stu_grade (
- stu_num number(10) primary key,
- branch varchar2(3) check(branch in('A','S','SP','AR')),
- grade_mat number(4,1) check(grade_mat<=150 and grade_mat>=0),
- grade_che number(4,1) check(grade_che<=150 and grade_che>=0),
- grade_eng number(4,1) check(grade_eng<=150 and grade_eng>=0),
- grade_inte number(4,1) check(grade_inte<=300 and grade_inte>=0)
- );
- insert into stu_grade values (2012100201,'S',139,114,98,251);
- insert into stu_grade values (2012100202,'S',79,96,81,212);
- insert into stu_grade values (2012100203,'S',112.5,88,149,229);
- insert into stu_grade values (2012100204,'S',87,94,82,181);
- insert into stu_grade values (2012100205,'S',76,90,67,101);
- insert into stu_grade values (2012100206,'S',138,141,150,281);
- insert into stu_grade values (2012100207,'S',88,94,123,61);
- insert into stu_grade values (2012100208,'S',97,42,80,119);
- insert into stu_grade values (2012100209,'S',39.5,24,48.5,62);
- insert into stu_grade values (2012100210,'S',110,80,82,180.5);
- insert into stu_grade values (2012100211,'S',97,88,109,200.5);
- insert into stu_grade values (2012100212,'S',138,74,28,281);
- insert into stu_grade values (2012211101,'A',112,138,143,201);
- insert into stu_grade values (2012211102,'A',97,124,138,219);
- insert into stu_grade values (2012211103,'A',72,64,98,123);
- insert into stu_grade values (2012211104,'A',139,144,150,257);
- insert into stu_grade values (2012211105,'A',121,113,111.5,198);
- insert into stu_grade values (2012211106,'A',100,74,72,81);
- insert into stu_grade values (2012211107,'A',71,84,91,151);
- insert into stu_grade values (2012211108,'A',127,144,146.5,232);
- insert into stu_grade values (2012211109,'A',76,114,56,99.5);
- insert into stu_grade values (2012311110,'A',19,81,84.5,51.5);
- insert into stu_grade values (2012341401,'SP',90,88,98.5,177);
- insert into stu_grade values (2012341402,'SP',39,64,51,70);
- insert into stu_grade values (2012341403,'SP',65,94,108,159);
- insert into stu_grade values (2012341404,'AR',99,110,98.5,251);
- insert into stu_grade values (2012341405,'AR',89,114,96,193);
- insert into stu_grade values (2012341406,'AR',29,76,99.5,201);
- insert into stu_grade values (2012341407,'AR',63,82,73,106);
5.建立提档线表(low_criterion)
- create table low_criterion(
- branch varchar2(3) check(branch in('A','S','SP','AR')),
- batch_id number(5),batch_name varchar2(10),low_cri number(4,1));
- insert into low_criterion values('S',1001,'BKYP',582);
- insert into low_criterion values('S',1002,'BKEP',430);
- insert into low_criterion values('A',1003,'BKYP',573);
- insert into low_criterion values('A',1004,'BKEP',450);
- insert into low_criterion values('SP',1005,'SPORT',399);
- insert into low_criterion values('AR',1006,'ART',300);
6.建立程序查询存储过程
- create or replace procedure pro_search_grade(stu_n in number)
- as
- pro_bra varchar2(3);
- grade_sum number(4,1):=0;
- pro_batch varchar2(10);
- max_low number(4,1):=0;
- pro_name varchar2(10);
- max_sum_grade number(4,1):=0;
- max_stu_name varchar2(10);
- max_stu_num number(10):=0;
- begin
- select stu_name into pro_name
- from stu_info where stu_num=stu_n;
- dbms_output.put('Student: ');
- dbms_output.put_line(pro_name);
- select branch into pro_bra
- from stu_grade where stu_num=stu_n;
- select grade_mat+grade_che+grade_eng+grade_inte into grade_sum
- from stu_grade where stu_num=stu_n;
- dbms_output.put('Your grade is ');
- dbms_output.put_line(grade_sum);
- select max(low_cri) into max_low
- from low_criterion
- where branch=pro_bra and grade_sum>=low_cri;
- if max_low>0 then
- select batch_name into pro_batch
- from low_criterion
- where low_cri=max_low;
- dbms_output.put('Congratulations to you for inetrnational ');
- dbms_output.put_line(pro_batch);
- else
- dbms_output.put_line('You will dead~');
- end if;
- select max(sum_grade) into max_sum_grade
- from
- (select grade_mat+grade_che+grade_eng+grade_inte sum_grade from stu_grade where branch=pro_bra);
- with tmp_t1
- as
- (select stu_num,grade_mat+grade_che+grade_eng+grade_inte sum_grade from stu_grade)
- select stu_num into max_stu_num
- from tmp_t1
- where sum_grade=max_sum_grade;
- select stu_name into max_stu_name
- from stu_info where stu_num=max_stu_num;
- dbms_output.put('The best student in this exap is ');
- dbms_output.put_line(max_stu_name);
- dbms_output.put('His grade is ');
- dbms_output.put_line(max_sum_grade);
- dbms_output.put('His Student Number is ');
- dbms_output.put_line(max_stu_num);
- end;
- /
#执行结果如下==================================
7.建立录取查询存储过程
- create or replace procedure pro_search_admit(stu_n in number)
- as
- grade_sum number(4,1):=0;
- wish_uni_grade number(4,1):=999;
- uni_num number(5):=0;
- univer_name varchar2(10);
- begin
- select grade_mat+grade_che+grade_eng+grade_inte into grade_sum
- from stu_grade where stu_num=stu_n;
- select fir_university_id into uni_num from stu_wish
- where stu_num=stu_n;
- select tmp_t1.low_cri into wish_uni_grade
- from university_info tmp_t1,stu_wish tmp_t2
- where tmp_t1.uni_id=tmp_t2.fir_university_id
- and tmp_t2.stu_num=stu_n;
- if wish_uni_grade>=grade_sum then
- wish_uni_grade := 999;
- end if;
- if wish_uni_grade = 999 then
- select sec_university_id into uni_num from stu_wish
- where stu_num=stu_n;
- select tmp_t1.low_cri into wish_uni_grade
- from university_info tmp_t1,stu_wish tmp_t2
- where tmp_t1.uni_id=tmp_t2.sec_university_id
- and tmp_t2.stu_num=stu_n;
- end if;
- if wish_uni_grade<=grade_sum then
- select uni_name into univer_name
- from university_info
- where uni_id=uni_num;
- dbms_output.put('Congratulations to you that you are admitted by ');
- dbms_output.put_line(univer_name);
- else
- dbms_output.put_line('Sorry,I have search so hardly,But not find any message!');
- end if;
- end;
- /
#执行结果如下==================