数据库系统原理(实验四)

  • 格式:doc
  • 大小:35.50 KB
  • 文档页数:8

沈 阳 工 程 学 院 学 生 实 验 报 告

(课程名称:数据库系统原理)

实验题目: 数据查询(二)

班 级计算机C131 学 号2013443133 姓 名 何鑫

日 期 2014-11-13地 点F608指导教师孙宪丽、李东鹏 一、实验目的

掌握SQL查询命令:包括连接查询、嵌套查询和集合查询。

二、实验环境

Oracle10g数据库系统。

三、实验内容与要求

使用Select命令完成下列数据查询。

一、连接查询

⑴查询每个学生及其选修课程的情况。

⑵查询男学生选修课成绩不及格的情况。

⑶查询计算机系学生选修课成绩不为空的情况。

⑷查询选修2号课程且分数在90分以上的所有学生。

⑸查询每个学生的学号,姓名,选课名及成绩。

⑹查询选修了课程,但没有参加考试(成绩为空)的学生学号,姓名,选课名及成绩。

二、嵌套查询

⑴查询与"张三"在同一系的学生。

⑵查询选修了课程名为"数据库"的学生学号和姓名。

三、EXISTS查询

⑴查询没有选修1号课程的学生的姓名。

⑵查询选修了所有课程的学生的姓名。

四、实验过程及结果分析

一(1)

select student.*,sc.* From student,sc Where student.sno=sc.sno;

结果:

(2)

select student.sno,sname,sage,sdept

From student ,sc

Where student.sno=sc.sno and student.ssex='男'

and student.grade<60;

结果:

ERROR at line 4:

ORA-00904: "STUDENT"."GRADE": invalid identifier

分析:student表中不存在grade字段.

改正:

select student.sno,sname,sage,sdept

From student ,sc

Where student.sno=sc.sno and student.ssex='男'

and sc.grade<60;

结果:

no rows selected

分析:男生中无不及格学生

(3)

select student.* From student,sc Where student.sno=sc.sno and

student.sdept='cs' and sc.grade is not null;

结果:

(4)

select * from sc,student where sc.sno=student .sno and o='2' and sc.grade>90; 结果:

no rows selected

分析:无九十分学生记录.

(5)

Select student.sno,sname,ame,grade from sc,course,student

where sc.sno=student.sno and o=o;

结果:

(6)

select student.sno,sname,sc.grade,ame From student,sc,course Where

student.sno=sc.sno and o =o and sc.grade is null ;

结果:

no rows selected

分析:无成绩为空记录。

二(1)

elect sno,sname,sdept

From student

Where sdept in

(select sdept

From student

Where sname='姚天驰');

结果:

SP2-0851: Command beginning "elect sno,..." is not available in iSQL*Plus

SP2-0851: Command beginning "From stude..." is not available in iSQL*Plus

SP2-0851: Command beginning "Where sdep..." is not available in iSQL*Plus no rows selected

分析:没有与张三所在同一系的记录。

(2)

select sno,sname From student Where sno in

(select sno From sc Where cno in

(select cno From course Cname=’数据库’));

ERROR at line 9:

ORA-00907: missing right parenthesis

分析:符号错误,’数据库’应为’Sx’.

改正:

select sno,sname From student Where sno in

(select sno From sc Where cno in

(select cno From course where Cname='Sx'));

结果:

三(1)

select sname From student Where not exists

(select * From sc Where sc.sno=student.sno and cno='1');

结果:

(2)

select sname From student Where not exists

(select * From course Where not exists

(select * From sc Where sc.sno=student.sno and o=o)); 结果:

no rows selected

分析:无选全部课程学生记录。

五、成绩评定

优 良 中 及格 不及格

出 勤

格 式

内 容

分 析

总 评

指导教师:

年 月 日