山东大学《数据库系统》实验六:视图操作

实验题目:创建视图、删除视图

实验目的:

oracle 管理平台,针对公共用户 pub 下的表,完成创建视图、查询验证视图、删除视图。视图名为 test6_(题号,题号长度两位,前面补零),例如 test6_01。

实验原理和方法:

例如:找出年龄小于 20 岁的所有学生的学号、姓名、年龄 正确执行:
create view test6_00 as select sid,name,age from pub.student where age>20
Oracle扩展后方便写法:create or replace view test6_00 as select sid,name,age from pub.student where age>20

同实验五:sql很简单,懒得改锁进了:)

实验步骤:

找出年龄小于 20 岁且是“物理学院”的学生的学号、姓名、院系名称,按学号排序。

create or replace view test6_01 as
select sid,name,dname
from pub.student
where age<20 and dname='物理学院'
order by sid 

查询统计 2009 级、软件学院每个学生的学号、姓名、总成绩(sum_score)。

create or replace view test6_02 as
select a.sid sid,a.name name,sum(b.score) sum_score
from pub.student a left join pub.student_course b
on a.sid=b.sid
where a.dname='软件学院' and a.class=2009
group by a.sid,a.name

查询 2010 级、计算机科学与技术学院、操作系统的学生成绩表,内容有学号、姓名、成绩。

create or replace view test6_03 as
select a.sid sid,a.name name,score
from pub.student a,pub.student_course b,pub.course c
where a.sid=b.sid and b.cid=c.cid 
and dname='计算机科学与技术学院' and class=2010
and c.name='操作系统'
找出选修“数据库系统”课程,且成绩大于 90 的学生的学号、姓名 
create or replace view test6_04 as
select a.sid sid,a.name name
from pub.student a,pub.student_course b,pub.course c
where a.sid=b.sid and b.cid=c.cid 
and score>90 and c.name='数据库系统'

找出姓名叫“李龙”的学生的学号及其选修全部课程的课程号、课程名和成绩。

create or replace view test6_05 as
select a.sid sid,b.cid cid,c.name name,score
from pub.student a,pub.student_course b,pub.course c
where a.sid=b.sid and b.cid=c.cid and a.name='李龙'

找出选修了所有课程的学生的学号、姓名

create or replace view test6_06 as
select sid,name
from pub.student a
where not exists
((select cid from pub.course)
Minus
(select cid from pub.student_course 
where sid=a.sid))

找出选修了所有课程并且所有课程全部通过的学生的学号、姓名

create or replace view test6_07 as
select sid,name
from pub.student a
where not exists
((select cid from pub.course)
minus
(select cid from pub.student_course 
where sid=a.sid and score>=60))

检索先行课的学分为 2 的课程号、课程名。

create or replace view test6_08 as
select a.cid cid,a.name name
from pub.course a,pub.course b 
where a.fcid=b.cid and b.credit=2

查询统计 2010 级、化学与化工学院的学生总学分表,内容有学号、姓名、总学分 sum_credit。

create or replace view test6_09 as
select a.sid sid,a.name name,sum(credit) sum_credit
from pub.student a,pub.student_course b,pub.course c
where a.sid=b.sid and b.cid=c.cid and score>=60
and class=2010 and dname='化学与化工学院'
group by a.sid,a.name

找出有间接先行课的所有课程的课程号、课程名称。

create or replace view test6_10 as
select a.cid cid,a.name name
from pub.course a,pub.course b
where a.fcid=b.cid and b.fcid is not null

结论分析与体会:

熟练掌握了视图的创建、查询验证和删除,oracle中create or replace解决了需要对错误视图首先进行删除再重复创建的问题。

就实验过程中遇到和出现的问题,你是如何解决和处理的,自拟1-3道问答题:

Q1:查询6:报错“ORA-00907: 缺失右括号”
Q2:exists拼错,一定要多加注意粗心错误,解决措施:不要对原sql语句进行复制粘贴,重新输入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宅女不减肥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值