oracle实验报告四川师范大学.doc
《oracle实验报告四川师范大学.doc》由会员分享,可在线阅读,更多相关《oracle实验报告四川师范大学.doc(34页珍藏版)》请在三一办公上搜索。
1、四川师范大学计算机学院实 验 报 告 册院系名称: 计算机科学学院 课程名称: Oracle 实验学期 2014 年至 2015 年 第 一 学期专业班级: 网络工程3班 姓名: 学号: 指导教师: 俞晓 实验最终成绩: 实验一 了解ORACLE环境,使用ORACLE数据库实用工具 1.目的要求: 了解ORACLE数据库的各个常用工具软件 2.实验内容: 在ORACEL数据库下使用SQL*PLUS ,SQL*PLUS Worksheet,PL/SQL Developer工具,企业管理器等实用工具与Oracle交互。并在企业管理器中观察ORACLE的底层存储原理。在PL/SQL Develope
2、r中书写简单的SQL语言。 3.主要仪器设备及软件 1)PC 2)ORACLE数据库 PL/SQL Developer工具的运用:实验二 熟悉SQL语言1.目的要求 在SQL*PLUS或PL/SQL Developer工具中编写SQL语句 2.实验内容 ORACLE 数据库中定义用户,给用户赋权限,创建,修改和删除表格,视图等数据库对象,并向表格中插入,修改和删除数据。体会SQL语言中ORACLE的“方言”。 对自己建立的表做查询:包括单表查询,多表查询,嵌套查询,分组查询,相关查询 掌握SQL语句的书写方法熟练使用SQL语句实现建表,修改表,删除表,向表中插入,删除,修改,查询等操作。1.
3、创建用户 create user LWQ identified by 123;2. 给用户赋权限 -连接权限: grant connect to LWQ; -登录数据库: connect LWQ/123; -建表权: grant create table to LWQ; -若想将权限赋予所有用户,可以使用Public角色。如: grant select on sc to public;收回权限:Revoke create table from LWQ; 3. 创建表Create Table Student(sno char(10) primary key ,sname varchar(20)
4、not null,sage smallint,ssex char(2),sdept varchar(20); Create Table Course (cno char(10), primary key (cno) ,cname varchar(20) , cpno char(10),credit smallint ); Create Table SC (sno char(10),cno char(10),grade smallint,primary key (sno, cno) ); 4. 修改表-向已经存在的表中添加属性: alter table student add avg_grade
5、 number;-删除一列:alter table student drop cloumn avg_grade;-修改属性及相应数据: alter table student modify sage varchar(30);5. 删除表格drop table student;6. DML数据库的修改: 向表中插入,删除,修改,查询等操作-向表中插入数据:insert into student values(001,张四,20,男,CS);insert into student values(002,刘五,19,女,IS);-删除数据:Delete from student where sno
6、= 001;-修改数据:update student set age = age + 1 where sno = 002;update sc set grade = 90 where sno = 001 and cno = 1001;-查询:select * from sc; select cno from course where cname=数据库; select * from student where sname like 李%;-为结果集中的某个属性改名:select pno as 产品号,pname 名字,place 产地 from p;-列出jkx系中的女生的学号、姓名、身高,并
7、按身高进行排列(降序): select sno,sname,heigh from student where sdept=jkx and ssex=女 order by heigh desc;-查询成绩小于60的10位同学的学号,课程号,成绩: select * from (select * from sc where grade60 order by grade desc) where rownum=10;7. 建视图-建立学生平均成绩视图:create view avg_grade(sno,avgs) as select sno,avg(grade) from sc group by sn
8、o-找出平均成绩小于89的学生select * from sc where avg(grade)=all(select sage from student);-2、求每一个学生的最高分和最低分。select sc.sno,sname,MAX(grade) Maxgrade,MIN(grade) Mingrade from sc,student where sc.sno=student.sno group by sc.sno,sname;-3、查询CS系所有男同学考C05课程的成绩,列出这些学生的学号,姓名,成绩,并按成绩降序排列。select student.sno,sname,grade f
9、rom sc,student where sc.sno=student.sno and sdept=CS and ssex=男 and cno=C05 order by grade desc;-4、检索选修了“数据库”课程的学生的姓名(可用子查询IN或Exists)select sname from student where exists (select * from sc where sno=student.sno and cno=( select cno from course where cname=数据库);select sname from student,sc,course wh
10、ere student.sno=sc.sno and o=o and cname=数据库-(方法二)select sname from student where sno in (select sno from sc where cno = ( select cno from course where cname=数据库);-(方法三)-5、检索选修了课程号为C01或C02课程,且成绩高于或等于70分的学生的姓名,课程名和成绩。select sname,cname,grade from student,sc,course where student.sno=sc.sno and o=o and
11、 o in (C01,C02) and grade = 70;-6、检索所有学生的姓名、所选课程的课程名和成绩以及课程号,并且按成绩的降序和课程号的升序进行排列(使用外连接将没有选课的同学列出来)。select sname,cname,o,grade from sc,student,course where sc.sno=student.sno and o=o order by grade desc, o asc;select student.sname,ame,sc.grade,o from ( student left join sc on (student.sno=sc.sno) lef
12、t join course on (o=o) order by sc.grade desc,o asc;-7. 列出没有选课的学生姓名select sname from student where not exists (select * from sc where sno=student.sno);-8. 列出平均分最高的学生所在系的所有学生的姓名select sname from student where sdept=( select sdept from student where sno=( select sno from sc group by sno having AVG(gra
13、de)=all(select AVG(grade) from sc group by sno);select * from student where sdept=CM;-(检查)-9.查询CS系C05课程的成绩比C05课程的平均分高的学生学号select student.sno,cno,grade from student,sc where student.sno=sc.sno and grade(select AVG(grade) from sc where cno=C05 group by cno) and sdept=CS and cno=C05;select student.sno,
14、cno,grade from sc,student where sc.sno=student.sno and cno=C05 and sdept=CS;-(测试)-10.查询既选修了C01又选修了C02的学生select sname from student where not exists (select * from course where cno in (C01,C02) and not exists (select * from sc where cno=o and sno=student.sno);-11.统计及格的课程数在四门以上的学生所选课程的平均成绩。最后按降序列出平均成绩名
15、次名单来。select sno,avg(grade) Agrade from sc where sno in ( select sno from sc where grade=60 group by sno having count(cno)4) group by sno order by avg(grade) desc;-12.检索所有CS系学生都选修了的课程(列出课程号) select cno from course wherenot exists (select * from student where sno in (select sno from student where sdep
16、t=CS) and not exists (select * from sc where sc.sno=student.sno and o=o);select sno,cno from sc where sno in (select sno from student where sdept =CS)-(检查)-13.查询年龄高于其所在系的平均年龄的学生姓名select sname,sdept from student x where sage( select Avg(sage) from student y where y.sdept=x.sdept);-14.查询每位同学的选课中成绩最高的课
17、程对应的学号,姓名,课程名,成绩select student.sno,Student.sname,ame,x.grade from Student,sc x,course where o=o and student.sno=x.sno and grade=( select max(grade) MAXgrade from sc y where y.sno=x.sno);-15.为MA系学生选修必修课C05 insert into sc(sno,cno) select sno,C05 from student where sdept = MA and not exists (select * f
18、rom sc where sno=student.sno and cno=C05);-16.将CS系,C01课程学生的成绩加10分update sc set grade=grade+10 where sno in (select sno from student where sdept=CS) and cno=C01;select * from sc where sno in (select sno from student where sdept=CS) and cno=C01-(检查)-17.将每位同学的最低分加10分(选)update sc set grade=grade+10 wher
19、e GRADE=(select min(grade) from sc x where sno=sc.sno)select sno,MIN(grade) from sc group by sno-(检查用)-18.将”数据库”的选课记录全部删除delete from sc where cno=(select cno from course where cname=数据库);实验三 实现简单的PL/SQL程序一.目的要求 编写简单的PL/SQL程序,熟悉PL/SQL编程环境 二.实验内容 在SQL*PLUS或PL/SQL Developer工具中编写PL/SQL的简单程序,熟悉PL/SQL的编程环
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- oracle 实验 报告 四川 师范大学

链接地址:https://www.31ppt.com/p-3426481.html