Oracle实验报告-学生选课数据库的设计与管理(共14页).doc
精选优质文档-倾情为你奉上华北电力大学科技学院实 验 报 告| 实验名称 学生选课数据库的设计与管理 课程名称 Oracle数据库系统应用 | 专业班级: 软件10K2 学生姓名:李运 学 号: 6 成 绩:指导教师: 实验日期:2013年5月10日 (实验报告如打印,纸张用A4,左装订;页边距:上下2.5cm,左2.9cm, 右2.1cm;字体:宋体小四号,1.25倍行距。)验证性、综合性实验报告应含的主要内容:一、实验目的及要求二、所用仪器、设备三、实验原理四、实验方法与步骤五、实验结果与数据处理 六、讨论与结论(对实验现象、实验故障及处理方法、实验中存在的问题等进行分析和讨论,对实验的进一步想法或改进意见)七、所附实验输出的结果或数据设计性实验报告应含的主要内容:一、设计要求二、选择的方案三、所用仪器、设备四、实验方法与步骤五、实验结果与数据处理 六、结论(依据“设计要求”)七、所附实验输出的结果或数据* 封面左侧印痕处装订专心-专注-专业一、实验目的及要求熟悉ORACLE的环境二、所用仪器、设备PC机和oracle编译软件三、实验方法与步骤用户管理:创建用户和用户授权:create user liyun1 identified by liyun1;grant sysdba to liyun1;grant create session to liyun1;创建表:1. 创建教师表:在教师表中,教师的tno号是唯一确定一位教师的,因此在表中设置为主键。教师表中包含教师的一些基本信息,教师号,教师名字,教师年龄,教师性别。create table teacher( tno varchar2(20) primary key, tname varchar2(20) not null, tage varchar2(10), tsex varchar2(5) check(tsex in('男','女');插入教师数据:insert into teacher values('95001','李云','35','男');insert into teacher values('95002','巩俐','32','女');insert into teacher values('95003','王涛','41','男');insert into teacher values('95004','刘备','35','男'');insert into teacher values('95005','张菲','40','女');insert into teacher values('95006','胖大海','39','男');insert into teacher values('95007','许攸','48','女');insert into teacher values('95008','关羽','51','男');insert into teacher values('95009','张三','35','女');insert into teacher values('95010','林云','37','女');2.创建学生表学生表中的学生号也是唯一雪顶一位学生的,因此也将学生号设置成为主键,该学生表中有学生号,学生姓名,学生年龄,学生性别属性。create table student( sno varchar(20) primary key , sname varchar(20) not null, sage varchar(10), ssex varchar(5) check(ssex in('男','女') );插入学生数据:insert into student values('10001','利好','22','男');insert into student values('10002','曹操','23','男');insert into student values('10003','三毛','21','男');insert into student values('10004','李宁','22','女');insert into student values('10005','司马光','24','男');insert into student values('10006','潘长江','20','女');insert into student values('10007','黄云','23','男');insert into student values('10008','力高','21','男');insert into student values('10009','阿里','24','男');insert into student values('10010','周杰伦','25','男');insert into student values('10011','大大','22','女');insert into student values('10012','娜迦','23','女');3创建课程表:课程表中课程号唯一确定课程,设置为主键,课程表中有课程的号码,课程的名字,课程的上课时间和上课地点。create table course( cno varchar(20) primary key , cname varchar(20) not null, ctime varchar(10), cplace varchar(50);插入课程数据:insert into course values('50001','数据库管理','21','教3_301');insert into course values('50002','面向对象设计','23','教3_211');insert into course values('50003','人工智能','41','教4_311');insert into course values('50004','计算机英语','44','教4_313');insert into course values('50005','软件工程','13','教3_305');insert into course values('50006','跆拳道','11','体育馆');insert into course values('50007','古希腊文化','54','教3_321');insert into course values('50008','中国历史','52','教3_101');insert into course values('50009','舞蹈','34','音乐管');insert into course values('50010','音乐','31','音乐馆');insert into course values('50011','c+','32','教3_205');insert into course values('50012','sql语言','14','教3_102');insert into course values('50013','网页设计','22','教3_106');4.创建关系表:在关系表中设置的是以上三个表的关系,在关系表中学生号,教师号,课程号,都设置为外键,以用来连接几个表。同时关系表中还有学生的课程成绩。create table sele( sno varchar(20), cno varchar(20), tno varchar2(20), grade int,foreign key(sno) references student(sno),foreign key(cno) references course(cno),foreign key(tno) references teacher(tno);插入关系数据:insert into sele values('10001','50003','95001','80');insert into sele values('10001','50006','95002','58');insert into sele values('10002','50002','95001','89');insert into sele values('10002','50003','95005','100');insert into sele values('10002','50001','95001','95');insert into sele values('10004','50009','95009','83');insert into sele values('10004','50010','95010','76');insert into sele values('10004','50011','95003','66');insert into sele values('10005','50008','95004','57');insert into sele values('10005','50001','95001','59');insert into sele values('10006','50010','95010','75');insert into sele values('10006','50012','95007','72');insert into sele values('10008','50007','95001','72');insert into sele values('10008','50003','95005','91');insert into sele values('10009','50003','95005','88');insert into sele values('10009','50005','95006','93');insert into sele values('10010','50001','95001','66');insert into sele values('10010','50004','95003','92');insert into sele values('10010','50006','95002','77');insert into sele values('10011','50009','95009','75');insert into sele values('10012','50013','95008','100');insert into sele values('10012','50007','95001','82');insert into sele values('10012','50010','95010','78');对库进行一些关系查询:1.用SQL语句查询至少教两门课的教师信息;用临时变量查询某个学生信息。查询至少教两门课的教师信息:select *from teacherwhere tno in(select tno from selegroup by tnohaving count(distinct (cno)>=2);查询某个学生信息:select sname,sage,sno,&&tempfrom student where sno=&temp;2.显示所有教师的信息:Set serveroutput onDeclare cursor my_cursor is select * from teacher;Begin for current_cursor in my_cursor loop dbms_output.put_line('教师号:'|current_cursor.tno|'教师姓名:'|current_cursor.tname|'教师年龄:'|current_cursor.tage|'教师性别:'|current_cursor.tsex); end loop;End;/3.过程实现如下功能:返回某门课学生的平均成绩(该课名称由参数传递)Set serveroutput oncreate or replace procedure search_avg(in_con in o%type)as out_grade int;Begin select avg(grade) into out_gradefrom sele,coursewhere o=o and cname=in_con; dbms_output.put_line('学生平均成绩:'|out_grade);End search_avg;/调用过程:execute search_avg('音乐');4.设计过程显示某位教师所教的学生(该教师名通过参数进行传递)。Set serveroutput oncreate or replace procedure myserach(pre in number)as cursor my_cursor is select sno,sname,sage,ssex from student where sno in (select sno from sele where tno = pre);Begin for current_cursor in my_cursor loop dbms_output.put_line('学生号:'|current_cursor.sno); dbms_output.put_line('学生姓名:'|current_cursor.sname); dbms_output.put_line('学生年龄:'|current_cursor.sage); dbms_output.put_line('学生性别:'|current_cursor.ssex); end loop;End myserach;/调用过程:execute myserach('95001');删除过程:drop procedure myserach;四、实验结果与数据处理用户创建和授权:教师表:学生表:课程表(一部分):关系表:查询至少教两门课的教师信息显示所有教师信息(一部分):用临时变量查询某个学生信息:返回某门课学生的平均成绩:显示某位教师所教的学生:五、讨论与结论 通过这次对学生选课数据库的设计,以及对数据库的安装和配置,sql的基本应用以及PL/SQL的应用。我对oracle有了更深的理解。对于oracle的配置也有了了解。学习到了如何在数据库中管理表对象,管理表中的数据以及根据系统业务规则处理表中的数据。在以后的学习中应当更加努力。