Oracle数据库应用与开发教材课后习题参考答案.docx
- 文档编号:18379437
- 上传时间:2023-04-24
- 格式:DOCX
- 页数:15
- 大小:20.53KB
Oracle数据库应用与开发教材课后习题参考答案.docx
《Oracle数据库应用与开发教材课后习题参考答案.docx》由会员分享,可在线阅读,更多相关《Oracle数据库应用与开发教材课后习题参考答案.docx(15页珍藏版)》请在冰豆网上搜索。
Oracle数据库应用与开发教材课后习题参考答案
1.8习题:
(1)关系型数据库管理系统,简称RDBMS。
。
(2)在关系型数据库中,标准二维表是基本的数据存储单元,里边存储了实体的属性和实体间的关系。
2.关系型数据库中,表与表之间包括的三种关系是:
一对一、一对多和多对多。
(1)一对一:
有两个表,表A和表B。
表A中的一条记录在表B中有一条记录与之对应。
反过来,表B中的一条记录在表A中也仅有一条记录与之对应。
(2)一对多:
有两个表,表A和表B。
表A中的一条记录在表B中有多条记录与之对应。
反过来,表B中的一条记录在表A中仅有一条记录与之对应。
(3)多对多:
有两个表,表A和表B。
表A中的一条记录在表B中有多条记录与之对应。
反过来,表B中的一条记录在表A中也有多条记录与之对应。
3.Oracle10g提供了四个版本,分别是:
Oracle10g标准版1、Oracle10g标准版、Oracle10g企业版、Oracle10g个人版。
(1)客户机/服务器结构:
简称C/S结构,是软件系统的一种体系结构。
数据库和数据库管理系统运行在服务器端,各种Oracle管理工具运行在客户机上,二者通过SQL*NET进行通信。
(2)浏览器/服务器结构:
简称B/S结构,是随着Web技术兴起后的一种新型软件系统结构。
它通常分为三层:
数据库服务器,用来存储和管理数据库;应用程序服务器,与数据库服务器进行交互完成各种数据处理工作;客户端浏览器,与应用程序服务器进行交互,负责提交数据处理请求并获得和显示结果。
(3)SYS:
该用户被默认创建并授予DBA角色,它是Oracle数据库中权限最大的管理员账号。
数据库中所有数据字典的基本表和视图都被存储在SYS的方案中,这些基本表和视图对于Oracle数据库的操作非常重要。
为了维护数据字典的正确性和完整性,SYS方案中的表只能由系统维护,不能被任何用户或数据库管理员修改,而且任何用户不能在SYS方案中创建表。
(4)SYSTEM:
被默认创建并授予DBA角色权限仅次于SYS。
该用户创建和管理数据库中可显示管理信息的表或视图,以及被Oracle数据库应用和工具使用的各种数据库对象。
(5)SYSMAN:
该用户是企业管理的超级管理员账号,该账号能够创建和修改其他管理员账号,同时也能管理数据库实例。
(6)DBSNMP:
是Oracle数据库中用于智能代理(IntelligentAgent)的用户,用来监控和管理数据库相关性能。
如果停止该用户,则无法提取相关的数据库信息。
(7)方法一:
点击“开始”—>“程序”—>“Oracle-
(8)方法二:
点击“开始”—>“运行”—>输入“cmd命令”—>进入DOS环境下执行SQLPLUS命令也可以打开SQL*Plus工具。
(9)方式三:
在IE浏览器地址栏中输入
2.6习题
一、填空题
1.数据、日志、控制、初始化参数数据控制初始化参数
2.表空间、段、盘区、数据块盘区数据块
3.数据段盘区
4.用户进程服务进程后台进程用户进程服务进程
5.数据重做日志
6.修改过的数据数据文件
7.重做日志缓冲区内的日志重做日志
8.日志条目归档日志设备归档
9.共享服务器专有服务器共享服务器共享服务器
二、简答题
1.Oracle数据库的物理存储结构式从物理组成的角度分析一个数据库在存储介质上的实际构成,它是由操作系统组织和管理的,是Oracle数据库的外部存储结构。
(1)数据文件:
数据文件时Oracle数据库用来存储各种数据的地方,如表中的记录、索引数据、系统数据和临时数据等。
(2)日志文件:
在Oracle中,日志文件记录了用户对数据的修改信息(如增加、删除、修改),名字通常为READ*.LOG格式。
(3)控制文件:
控制文件时Oracle数据库的物理文件之一,它是一个很小的二进制文件,记录了数据库的名称、数据文件和连击日志文件的名称及位置、当前的日志序列号、表空间等信息。
(4)参数文件:
参数文件中记录着数据库名称、控制文件的路径、SGA的内存结构、可选的Oracle特性和后台进程的配置参数等信息。
(1)Oracle数据库逻辑存储结构是Oracle数据库创建后利用逻辑概念来描述数据库内部数据的组织和管理形式。
包括表空间、段、区和块四种。
(2)表空间和数据文件的关系:
数据库中的一个表空间至少包含一个或多个数据文件,而一个数据文件只能属于一个表空间。
这种关联实现了数据库的逻辑存储结构和物理存储结构的统一。
(1)数据库实例是用户访问数据库的中间层,是使用数据库的手段,它为用户访问数据库提供了必要的内存空间和多个Oracle进程,它是动态的、临时的。
一个Oracle实例由内存空间和Oracle进程两部分组成。
(2)数据库和数据库实例是相辅相成、缺一不可的。
如果只有数据库的物理文件,只能说明有数据被存储在数据库中,但是无法直接访问。
如果只有数据库实例,说明为数据库的使用做好了准备、可以访问数据库,但不知道要操作的数据在哪里。
(1)客户端配置
a)sqlnet.ora文件用于指定数据库连接账号的验证方式以及连接字符串的解析方式,也就是说通过该文件决定怎样查找一个连接中出现的连接字符串的定义。
b)tnsnames.ora文件时Oracle客户端的另一个重要文件,用来定义客户端连接远程服务器时的主机字符串。
(2)服务器端配置
一、listener.ora文件作用于Oracle数据库服务器端,是Oracle监听服务的配置文件。
当客户端向服务器提交连接请求时,由监听服务接受并对连接账号进行有效验证,验证通过后将用户进程交给服务进程处理。
若该文件被破坏,将影响监听服务的正常使用。
3.5习题
一、选择题
1.C2.C3.B
二、简答题
1.一个方案只能被一个数据库用户拥有,并且方案名称与这个用户的名称相同。
创建新用户时系统自动创建该用户的方案。
数据库的每一个用户都拥有一个唯一的方案。
该用户创建的方案对象默认被保存在自己的方案中。
2.CREATEUSER创建新用户命令:
(1)USER-NAME:
新创建的用户名称。
(2)PASSWORD:
为新用户制定密码。
(3)DEFAULTTABLESPACE:
为新用户指定默认表空间。
用来储存该用户创建的方案对象。
(4)TEMPORARYTABLESPACE:
为用户指定临时表空间,存储操作过程中产生的临时数据。
(5)QUOAT:
为新用户指定磁盘配额,表示该用户在指定的空间中可以占用的最大磁盘空间。
(6)UNLIMITED:
表示该用户可以使用无限大的空间。
(7)PROFILE:
指定新用户使用的配置文件。
(8)PASSWORDexpire:
表示新用户密码过期,登陆后需要给出新密码。
(9)ACCOUNTlock/unlock:
表示用户加锁/解锁状态。
其中,用户名和密码是必须有的。
三、操作题
1.CREATEUSERORA_TEMP
IDENTIFIEDBYTEM;
2.ALTERUSERORA_TEMP
IDENTIFIEDBYORA;
3.ALTERUSERORA_TEMP
ACCOUNTLOCK;
4.5实验
a)createtablestudent(
snochar(10)primarykey,
snamevarchar2(8),
sexchar
(2)default'男'check(sex='男'orsex='女'),
birthdaydate,
sdeptchar(20)
);
b)createtablecourse(
cnochar(10)primarykey,
cnamechar(30)unique,
ccreditnumber(3)
);
c)createtablescore(
snochar(10)referencesstudent(sno),
cnochar(10)referencescourse(cno),
gradenumber(3)check(grade>=0andgrade<=100),primarykey(sno,cno)
);
d)altertablestudent
add(memovarchar2(200));
e)altertablestudent
modify(memovarchar2(300));
f)altertablestudent
dropcolumnmemo;
insertintostudentvalues('001','zhang','女','01-7月-1992','生活部');
insertintostudentvalues('001','lisi','女','11-5月-1992','艺术部');
insertintostudentvalues('002','wang',default,'21-8月-1992','外联部');
insertintocoursevalues('1001','文学','88');
insertintocoursevalues('1002','文学','99');
insertintocoursevalues('1001','经济','89');.
insertintoscorevalues('001','1001','6');
insertintoscorevalues('001','1001','7');
insertintoscorevalues('002','1001','8');
g)updatescoresetsno='003'wheregrade='8';
updatescoresetcno='1003'wheresno='002';
h)deletefromstudentwheresname='lisi';
i)管理---方案---表---在“方案”和“对象名”文本框中输入要删除的方案名或表名,选择需要删除的表,单机“删除”。
j)droptablestudent;
4.6习题
1.AB2.B3C4.A5.B
6.C7A8C9.B10.A
5.5实验
(1)select*fromscott.empwheredeptno=20;
(2)selectempno,ename,deptnofromscott.empwherejob='CLERK';
(3)select*fromscott.empwherecomm>sal;
(4)select*fromscott.empwherecomm>sal*0.2;
(5)select*fromscott.empwhere(deptno=10andjob='MANAGER')or(deptno=20andjob='CLERK');
(6)select*fromscott.empwherejobnotin('MANAGER','CLERK')andsal>=2000;
(7)select*fromscott.empwherecommisnotnull;
(8)selectcount(empno),avg(sal)fromscott.emp;
(9)select*fromscott.empwherecommisnullorcomm<100
(10)select*fromscott.empwhere(sysdate-hiredate)/365<=2;
(11)select*fromscott.empwhere(sysdate-hiredate)/365>=10;
(12)selectinitcap(lower(ename))fromscott.emp;
(13)select*fromscott.empwherelength(ename)=6;
(14)select*fromscott.empwhereenamenotlike'%S%';
(15)select*fromscott.empwhereenamelike'_M%';
(16)selectsubstr(ename,1,3)fromscott.emp;
(17)selectreplace(ename,'s','S')fromscott.emp;
(18)selectename,hiredatefromscott.emporderbyhiredate;
(19)selectename,job,salfromscott.emporderbyjobdesc,salasc;
(20)selectename,extract(yearfromhiredate)as年份,extract(monthfromhiredate)as月份fromscott.emporderby月份,年份;
(21)selectdeptno,count(*),avg(sal),avg((sysdate-hiredate)/365)fromscott.empgroupbydeptno;
(22)selectcount(*),avg(sal)fromscott.empgroupbydeptno;
(23)selectmin(sal),jobfromscott.empgroupbyjobhavingmin(sal)<3000;
(24)selectdeptno,job,max(sal)fromscott.empgroupbydeptno,job;
(25)selectcount(*),avg(sal)fromscott.empgroupbyjob;
5.6习题
1.C2.A3.A4.A5.C6.A7.B8.C9.A10.B
6.5习题
(1)
selectename,dnamefromscott.empt1innerjoinscott.deptt2ont1.deptno=t2.deptnowherejob='CLERK';
(2)
select*fromscott.empt1rightjoinscott.deptt2ont1.deptno=t2.deptno
(3)
select*fromscott.empt1leftjoinscott.deptt2ont1.deptno=t2.deptno
(4)
用子查询实现:
select*fromscott.empwheredeptno=(selectdeptnofromscott.deptwheredname='SALES')
用连接查询实现:
select*fromscott.empt1innerjoinscott.deptt2ont1.deptno=t2.deptnowheret2.dname='SALES';
注意两种实现方式,在行和列上的变化。
(5)简单自连接
selectt1.enameas员工姓名,t2.ename经理姓名fromscott.empt1,scott.empt2wheret1.mgr=t2.empno;
(6)
selectt1.enameas员工姓名,t2.ename经理姓名fromscott.empt1,scott.empt2wheret1.mgr=t2.empnoandt1.hiredate (7) selectt1.ename,t1.job,t1.deptno,t2.ename,t2.job,t2.deptnofromscott.empt1crossjoinscott.empt2wheret1.job=t2.jobandt1.deptno<>t2.deptno (8) selectt1.enameas员工姓名,t2.ename经理姓名fromscott.empt1,scott.empt2wheret1.mgr=t2.empnoandt1.deptno=10; (9) select*fromscott.empwheresal>2500 union select*fromscott.empwherejob='ANALYST' (10) select*fromscott.empwheresal>2500 intersect select*fromscott.empwherejob='ANALYST' (11) select*fromscott.empwheresal>2500 minus select*fromscott.empwherejob='ANALYST'; (12) select*fromscott.empwheresal>(selectavg(sal)fromscott.emp) (13) select*fromscott.empwherejob=(selectjobfromscott.empwhereename='SMITH') (14) select*fromscott.empwheresal>(selectsalfromscott.empwhereename='SMITH') (15) selectename,salfromscott.empwheresal>all(selectsalfromscott.empwheredeptno=30) (16) select*fromscott.empwheredeptnoin(selectdeptnofromscott.empgroupbydeptnohavingcount(*)>5); (17) select*fromscott.deptwheredeptnoin(selectdeptnofromscott.empgroupbydeptnohavingmin(sal)>2000) (18)本题的关键是使用子查询作为数据源和查询的条件,可以从最里层的子查询开始理解 select*fromscott.deptwheredeptnoin(selectdeptnofrom(selectdeptno,count(*)as人数fromscott.empgroupbydeptno)where人数=(selectmax(人数)from(selectdeptno,count(*)as人数fromscott.empgroupbydeptno))); (19) select*fromscott.deptwheredeptnoin(selectdeptnofromscott.empgroupbydeptnohavingcount(*)>=1) (20)本题关键是使用相关子查询做条件 select*fromscott.empewheresal>(selectavg(sal)fromscott.empgroupbydeptnohavinge.deptno=deptno); (21)本题关键是使用两个子查询的结果进行内连接查询 select*from((select*fromscott.empewheresal>(selectavg(sal)fromscott.empgroupbydeptnohavinge.deptno=deptno))t1innerjoin (selectavg(sal),deptnofromscott.empgroupbydeptno)t2ont1.deptno=t2.deptno); (22) select*fromscott.deptwheredeptnoin(selectdistinctdeptnofromscott.empwhereempnoin(selectdistinctmgrfromscott.emp)); (23) select*fromscott.empt1,scott.deptt2wheret1.deptno=t2.deptnoandt1.deptnoin(selectdeptnofromscott.empgroupbydeptnohavingavg(sal)<2000) 7.10习题 一、 1.执行部分 2.RAISE 二、 1.D2.B3.CE4.A5.B 1. loop循环实现: declare inumberdefault1; snumberdefault0; begin loop s: =s+i; i: =i+1; exitwheni>100; endloop; dbms_output.put_line('和是: '||s); end; whlie循环实现: declare inumberdefault1; snumberdefault0; begin whilei<=100loop s: =s+i; i: =i+1; endloop; dbms_output.put_line('和是: '||s); end; for循环实现: declare snumberdefault0; begin foriin1..100loop s: =s+i; endloop; dbms_output.put_line('和是: '||s); end; 2. 显示游标的for循环: declare cursorcur1isselectename,salfromscott.emp; begin forrecincur1loop dbms_output.put_line(rec.ename||''||rec.sal); endloop; end; 隐式游标的for循环: begin forrecin(selectename,salfromscott.emp)loop dbms_output.put_line(rec.ename||''||rec.sal); end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Oracle 数据库 应用 开发 教材 课后 习题 参考答案