版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精品文档Oraclellg数据库基础教程参考答案第5章数据库存储设置与管理P70 .实训题(8)为USER表空间添加一个数据文件, 文件名为USERS05.DBF大小为50MBALTER TABLESPACE USERS ADD DATAFILE D:ORACLEORADATAORCL%users05.dbf SIZE 50M;(9)为EXAMPL表空间添加一个数据文件,文件名为 example05.dbf,大小为20MBALTER TABLESPACE EXAMPLEADD DATAFILE D:ORACLEORADATAORCLexample05.dbf SIZE 20M;(10)修改US
2、ER表空间中的userdata05.dbf 为自动扩展方式,每次扩展5MB最大为100MBALTER DATABASE DATAFILE D:ORACLEORADATAORCL%userdata05.dbf AUTOEXTEND ON NEXT 5M MAXSIZE 100M;(14)为数据库添加一个重做日志文件组, 组内包含两个成员文件,分别为redo5a.log 和 redo5b.log,大小分别为 5MBALTER DATABASE ADD LOGFILE GROUP 5( D:ORACLEORADATAORCLredo5a.log , D:ORACLEORADATAORCLredo5b
3、.lo' )SIZE 5M;(15) 为新建的重做日志文件组添加一个成员文件,名称为 redo5c.log 。ALTER DATABASE ADD LOGFILE MEMBER D:ORACLEORADATAORCLredo5c.log TO GROUP 5;(16) 将数据库设置为归档模式,并采用自动归档方式。SHUTDOWN IMMEDIATE STARTUP MOUNTALTER DATABASE ARCHIVELOG;ALTER DATABASE OPEN;ALTER SYSTEM ARCHIVE LOG START(8)ALTER TABLESPACE USERSADD DA
4、TAFILE D:ORACLEORADATAORCLuserdata05.dbfSIZE 50M'(9)ALTER TABLESPACE EXAMPLEADD DATAFILE D:ORACLEORADATAORCLexample05.dbfSIZE 20M'(10)ALTER DATABASE DATAFILE):ORACLEORADATAORCLuserdata05.dbf AUTOEXTEND ONNEXT 5M MAXSIZE 100M;(14)ALTER DATABASE ADD LOGFILE GROUP(D:ORACLEORADATAORCLredo05a.log
5、 'D:ORACLEORADATAORCLredo05b.lo6SIZE 5M;(15)ALTER DATABASE ADD LOGFILE MEMBERD:ORACLEORADATAORCLredo05c.logTO GROUP 5;(16)SHUTDOWN IMMEDIATESTARTUP MOUNTALTER DATABASE ARCHIVELOG;ALTER DATABASE OPEN;ALTER SYSTEM ARCHIVE LOG START第6章数据库对象的创建与管理2 .实训题(2)Create table exer_class(CNO number(2) primar
6、y key,CNAME varchar2(20),NUM number(3)Create table exer_student(SNO number(4) primary key,SNAME varchar2(10) unique,SAGE number,SEX char(2),CNO number(2)(3)Alter table exer_student add constraint ck_sage check (sage>0 and sagev=100);(4)alter table exer_student add constraint ck_stu check(sex='
7、;M' or sex='F')modify sex default 'M'(5)Create unique index ind_cname on exer_class(cname);(6)Create view s_c asSelect sno,sname,sage,sex,o,cname,numFrom exer_class c join exer_student sOn o=o;(7)Create sequence sequl start with 100000001;(8)create table exer_student_range(sno nu
8、mber(4) primary key,sname varchar2(10),sage number,sex char(2),cno number(2)partition by range(sage)(partition parti values less than(20) tablespace example,partition part2 values less than(30) tablespace orcltbsi,partition part3 values less than(maxvalue) tablespace orcltbs2)(9)create table exer_st
9、udent_list(sno number(4) primary key,sname varchar2(10),sage number,sex char(2),cno number(2) partition by list(sex)(partition man values('M') tablespace orcltbs1, partition woman values('F') tablespace orcltbs2)(10)Create index ind on exer_student_range(sno) local;第9章PL/SQL语言基础1 .实训
10、题(1)declarecursor c_emp is select * from employees;beginfor v_emp in c_emp loopdbms_output.put_line(v_emp.first_name |v_emp.last_name'| v_emp.employee_id '|v_emp.salary '|v_emp.department_id);end loop;end;(2)declarev_avgsal employees.salary%type;beginfor v_emp in (select * from employees
11、) loopselect avg(salary) into v_avgsal from employeeswhere department_id=v_emp.department_id;if v_emp.salary>v_avgsal then dbms_output.put_line(v_emp.first_name '|v_emp.last_name'| v_emp.employee_id '|v_emp.salary '|v_emp.department_id);end if;end loop;end;(3)declarecursor c_emp i
12、sselect e.employee_id eid,e.last_name ename,e.department_id edid,m.employee_id mid,m.last_name mname from employees e join employees m on e.manager_id=m.employee_id;v_emp c_emp%rowtype;beginopen c_emp;loopfetch c_emp into v_emp;exit when c_emp%notfound;dbms_output.put_line(v_emp.eid '|v_emp.enam
13、e'| v_emp.edid |v_emp.mid |v_emp.mname);end loop;close c_emp;end;(4)declarev_emp employees%rowtype;beginselect * into v_emp from employees where last_name='Smith' dbms_output.put_line(v_emp.employee_id'|v_emp.first_name '|v_emp.last_name'| v_emp.salary '|v_emp.department_
14、id);exceptionwhen no_data_found theninsert into employees(employee_id,last_name,salary,email,hire_date, job_id,department_id)values(2010,'Smith',7500,'smith', to_date('2000-10-5','yyyy-mm-dd'),'AD_VP',50);when too_many_rows thenfor v_emp in(select * from emplo
15、yees where last_name='Smith')loop dbms_output.put_line(v_emp.employee_id'|v_emp.first_name '|v_emp.last_name'| v_emp.salary '|v_emp.department_id);end loop;end;第10章PL/SQL程序设计(1)创建一个存储过程,以员工号为参数,输出该员工的工资。create or replace procedure pro_showsal(p_empno employees.employee_id%typ
16、e)asv_sal employees.salary%type;beginselect salary into v_sal from employeeswhere employee_id=p_empno;dbms_output.put_line(v_sal);exceptionwhen no_data_found thendbms_output.put_line('there is not such an employees');end;beginpro_showsal(100);end;10号部门,则工资增(2) 创建一个存储过程,以员工号为参数,修改该员工的工资。若该员工属
17、于则工资增加140元;若属于20号部门,则工资增加 200元;若属于30号部门, 加250元;若属于其他部门,则工资增长300元。create or replace procedure pro_updatesal(p_empno employees.employee_id%type)asv_deptno employees.department_id%type;v_inc number;beginselect department_id into v_deptno from employeeswhere employee_id=p_empno;case v_deptnowhen 10 then
18、 v_inc:=140;when 20 then v_inc:=200;when 30 then v_inc:=250;else v_inc:=300;end case;update employees set salary=salary+v_incwhere employee_id=p_empno;exceptionwhen no_data_found thendbms_output.put_line('there is not such an employees'); end;(5)创建一个包,包中包含一个函数和一个过程。函数以部门号为参数,返回该部门员工 的最高工资;过程
19、以部门号为参数,输出该部门中工资最高的员工名、员工号。create or replace package pkg_empasfunction func_ret_maxsal(p_deptno number) return number;procedure pro_showemp(p_deptno number);end;create or replace package body pkg_empasfunction func_ret_maxsal(p_deptno number) return numberasv_maxsal number;beginselect max(salary) in
20、to v_maxsal from employeeswhere department_id=p_deptno;return v_maxsal;end;procedure pro_showemp(p_deptno number) ascursor c_emp is select * from employees where department_id=p_deptno and salary=func_ret_maxsal(p_deptno);beginfor v_emp in c_emp loopdbms_output.put_line(v_emp.employee_id'|v_emp.
21、salary);end loop;end;end;(6)创建一个包,包中包含一个过程和一个游标。游标返回所有员工的信息;存储过程实 现每次输出游标中的 5条记录。create or replace package pkg_showempascursor c_emp is select * from employees;procedure show_fiveemp;end;create or replace package body pkg_showempasprocedure show_fiveempasv_emp c_emp%rowtype;beginif not c_emp%isopen
22、then open c_emp;end if;for i in 1.20 loopfetch c_emp into v_emp;if c_emp%notfound thenclose c_emp;exit;end if;dbms_output.put_line(v_emp.employee_id'|v_emp.first_name);end loop;end;end;beginpkg_showemp.show_fiveemp;end;(7)在employees表上创建一个触发器,保证每天8: 0017: 00之外的时间禁止对该表 进行DML操作。create or replace tr
23、igger trg_empbefore insert or update or delete on employeesdeclarebeginif to_char(sysdate,'HH24:MI')not between '08:00' and '17:00' then raise_application_error(-20000,'此时间内,不允许修改EMPLOYEES表');end if;end;(8) 在employees表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门 的人数及平均工资,并输出。create
24、 or replace trigger trg_8after insert or update or deleteon employeesdeclarecursor c_dept isselect department_id,avg(salary) avgsal,count(*) numfrom employees group by department_id;beginfor v in c_dept loopdbms_output.put_line(v.department_id'|v.avgsal| |''|v.num);end loop;end;第13章安全管理2
25、 .实训题(1)CREATEUSERusera_exer IDENTIFIED BY usera DEFAULTTABLESPACESERSQUOTA 10M ON USERS ACCOUNT LOCK;(2)CREATE USER userb_exer IDENTIFIED BY userb;(3)GRANT CREATE SESSION TO usera_exer WITH ADMIN OPTION;GRANT SELECT UPDATE ON ehr.employees TO usera_exer WITH GRANT OPTION;(4)ALTER USER usera_exer AC
26、COUNT UNLOCK;(5)CONNECT usera_erer/useraSELECT * FROM ehr.employees;UPDATE ehr.employees SET salary=salary+100 ;GRANT SELECT ,UPDATE ON ehr.employees TO userb_exer;(6)REVOKE CREATE SESSION FROM usera_exer;GRANT CREATE SESSION TO usera_exer;(7)REVOKE SELECT,UPDATE ON ehr.employees FROM usera_exer;GRA
27、NT SELECT ,UPDATE ON ehr.employees TO usera_exer;(8)CREATE ROLE rolea;CREATE ROLE roleb;GRANT CREATE TABLE TO rolea;GRANT INSERT,UPDATE ON ehr.employees TO rolea;GRANT CONNECT ,RESOURCE TO roleb;(9)GRANT rolea,roleb TO usera_exer;(10)CREATE PROFILE pwdfileLIMIT CONNECT_TIME 30IDLE_TIME 10 FAILED_LOG
28、IN_ATTEMPTS 4PASSWORD_LIFE_TIME 20 PASSWORD_LOCK_TIME 10ALTER USER usera_exer PROFILE pwdfile;第14章备份与恢复2 .实训题(1 )对human_resource数据库进行冷备份。(2 )对human_resource数据库进行一次完全的热备份。(3)备份human_resource数据库的控制文件。(4) 假定human_resource数据库丢失了数据文件usersOl.dbf,使用数据库热备份对数据库 进行恢复,并验证恢复是否成功。(8)使用expdp命令导出human_resource数据库的
29、ehr模式下的所有数据库对象。第15章备份与恢复假设2013-3-12日在数据库中执行了下列操作。略略略(课本可看)(P254)(5)利用闪回查询,查询 15: 40: 10时exercise中的数据(6) 利用闪回版本查询,查询15: 35 : 1015: 42: 10之间sno =100的记录版本信息(7 )利用闪回表技术,将exercise表恢复到删除操作进行之前的状态(8) 执行"DROP TABLE exerciS”语句 然后利用闪回删除技术恢复exercise表(9)将数据库中的闪回日志保留时间设置为 3天(4320分钟)(10)利用闪回数据库技术,将数据库恢复到创造表之前的状态set time oncreate table flash_table(id NUMBER PRIMARY KEYn ame CHAR(20);in sert into flash_table values(100,'jack');commit;in sert into flash_table values(200,'k in g');commit;in sert into flash_ta
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 医疗行业人力资源主管的工作要点
- 企业内部合规律师的角色与职责探讨
- 金融分析师招聘面试全流程及技巧指导
- 中小学航空演讲稿
- 2025年AI艺术生成工程师的职业网络拓展方法
- 运动员英文介绍演讲稿
- 正能量激励短演讲稿
- 文化自信冬奥会演讲稿
- 以自律浇灌青春演讲稿
- 人生梦想的启示演讲稿
- 成套设备全生命周期管理手册
- 2026马年《开学第一课:龙马精神 梦想起航》教学课件
- 2026年甘肃省公信科技有限公司面向社会招聘80人(第一批)笔试备考试题及答案解析
- 2026季华实验室科研部门招聘5人(广东)笔试参考题库及答案解析
- 2026中央机关遴选和选调公务员调剂参考考试试题附答案解析
- 纯水设备工艺培训课件
- 制造企业保持业务连续性实施方案
- 工程部介绍教学课件
- 虚拟电厂与车网互动的未来发展场景研究
- 扣眼穿刺的临床应用
- 初中新课标解读培训课件
评论
0/150
提交评论