《Oracle11g数据库基础教程课后习题答案(共13页).doc》由会员分享,可在线阅读,更多相关《Oracle11g数据库基础教程课后习题答案(共13页).doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上Oracle11g数据库基础教程参考答案第5章 数据库存储设置与管理P70实训题(8)为USERS表空间添加一个数据文件,文件名为USERS05.DBF,大小为50MB。 ALTER TABLESPACE USERS ADD DATAFILE D:ORACLEORADATAORCL%users05.dbf SIZE 50M;(9)为EXAMPLE表空间添加一个数据文件,文件名为example05.dbf,大小为20MB。 ALTER TABLESPACE EXAMPLE ADD DATAFILE D:ORACLEORADATAORCLexample05.dbf SIZ
2、E 20M;(10)修改USERS表空间中的userdata05.dbf为自动扩展方式,每次扩展5MB,最大为100MB。 ALTER DATABASE DATAFILE D:ORACLEORADATAORCL%userdata05.dbf AUTOEXTEND ON NEXT 5M MAXSIZE 100M; (14)为数据库添加一个重做日志文件组,组内包含两个成员文件,分别为redo5a.log和redo5b.log,大小分别为5MB。 ALTER DATABASE ADD LOGFILE GROUP 5 (D:ORACLEORADATAORCLredo5a.log, D:ORACLEOR
3、ADATAORCLredo5b.log)SIZE 5M; (15)为新建的重做日志文件组添加一个成员文件,名称为redo5c.log。 ALTER DATABASE ADD LOGFILE MEMBER D:ORACLEORADATAORCLredo5c.log TO GROUP 5; (16)将数据库设置为归档模式,并采用自动归档方式。 SHUTDOWN IMMEDIATE STARTUP MOUNT ALTER DATABASE ARCHIVELOG; ALTER DATABASE OPEN; ALTER SYSTEM ARCHIVE LOG START(8)ALTER TABLESPAC
4、E USERSADD DATAFILE D:ORACLEORADATAORCLuserdata05.dbf SIZE 50M;(9)ALTER TABLESPACE EXAMPLEADD DATAFILE D:ORACLEORADATAORCLexample05.dbf SIZE 20M;(10)ALTER DATABASE DATAFILE D:ORACLEORADATAORCLuserdata05.dbf AUTOEXTEND ON NEXT 5M MAXSIZE 100M; (14)ALTER DATABASE ADD LOGFILE GROUP 5 (D:ORACLEORADATAOR
5、CLredo05a.log,D:ORACLEORADATAORCLredo05b.log)SIZE 5M;(15)ALTER DATABASE ADD LOGFILE MEMBER D:ORACLEORADATAORCLredo05c.log TO 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
6、(2) primary 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 (sage0 and sagev_avgsal then dbms_output.put_line(v_emp.first_name| |v_emp.last_
7、name| | v_emp.employee_id| |v_emp.salary| |v_emp.department_id); end if; end loop;end;(3)declare cursor c_emp is select 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;b
8、egin open c_emp; loop fetch c_emp into v_emp; exit when c_emp%notfound; dbms_output.put_line(v_emp.eid| |v_emp.ename| | v_emp.edid| |v_emp.mid| |v_emp.mname); end loop; close c_emp;end;(4)declare v_emp employees%rowtype;begin select * into v_emp from employees where last_name=Smith; dbms_output.put_
9、line(v_emp.employee_id| | v_emp.first_name| |v_emp.last_name| | v_emp.salary| |v_emp.department_id);exception when no_data_found then insert 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
10、too_many_rows then for v_emp in(select * from employees 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_
11、empno employees.employee_id%type)as v_sal employees.salary%type;begin select salary into v_sal from employees where employee_id=p_empno; dbms_output.put_line(v_sal);exception when no_data_found then dbms_output.put_line(there is not such an employees);end;begin pro_showsal(100);end;(2)创建一个存储过程,以员工号为
12、参数,修改该员工的工资。若该员工属于10号部门,则工资增加140元;若属于20号部门,则工资增加200元;若属于30号部门,则工资增加250元;若属于其他部门,则工资增长300元。create or replace procedure pro_updatesal( p_empno employees.employee_id%type)as v_deptno employees.department_id%type; v_inc number;begin select department_id into v_deptno from employees where employee_id=p_e
13、mpno; case v_deptno when 10 then 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_inc where employee_id=p_empno;exception when no_data_found then dbms_output.put_line(there is not such an employees);end;(5)创建一个包,包中包含一个函数和一个
14、过程。函数以部门号为参数,返回该部门员工的最高工资;过程以部门号为参数,输出该部门中工资最高的员工名、员工号。create or replace package pkg_empas function func_ret_maxsal(p_deptno number) return number; procedure pro_showemp(p_deptno number);end;create or replace package body pkg_empas function func_ret_maxsal(p_deptno number) return number as v_maxsal
15、number; begin select max(salary) into v_maxsal from employees where department_id=p_deptno; return v_maxsal; end; procedure pro_showemp(p_deptno number) as cursor c_emp is select * from employees where department_id=p_deptno and salary=func_ret_maxsal(p_deptno); begin for v_emp in c_emp loop dbms_ou
16、tput.put_line(v_emp.employee_id| | v_emp.salary); end loop; end;end;(6)创建一个包,包中包含一个过程和一个游标。游标返回所有员工的信息;存储过程实现每次输出游标中的5条记录。create or replace package pkg_showempas cursor c_emp is select * from employees; procedure show_fiveemp;end;create or replace package body pkg_showempas procedure show_fiveemp as
17、 v_emp c_emp%rowtype; begin if not c_emp%isopen then open c_emp; end if; for i in 1.20 loop fetch c_emp into v_emp; if c_emp%notfound then close c_emp; exit; end if; dbms_output.put_line(v_emp.employee_id| | v_emp.first_name); end loop; end;end;begin pkg_showemp.show_fiveemp;end;(7)在employees表上创建一个触
18、发器,保证每天8:0017:00之外的时间禁止对该表进行DML操作。create or replace trigger trg_empbefore insert or update or delete on employeesdeclarebeginif to_char(sysdate,HH24:MI)not between 08:00 and 17:00 thenraise_application_error(-20000,此时间内,不允许修改EMPLOYEES表);end if;end;(8)在employees表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资
19、,并输出。create or replace trigger trg_8after insert or update or deleteon employees declare cursor c_dept is select department_id,avg(salary) avgsal,count(*) num from employees group by department_id;begin for v in c_dept loop dbms_output.put_line(v.department_id| | v.avgsal| |v.num); end loop; end;第13
20、章 安全管理 2实训题(1)CREATE USER usera_exer IDENTIFIED BY usera DEFAULT TABLESPACE USERS QUOTA 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
21、usera_exer ACCOUNT 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 u
22、sera_exer;GRANT 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 30 IDLE_TIM
23、E 10 FAILED_LOGIN_ATTEMPTS 4 PASSWORD_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数据库丢失了数据文件users01.dbf,使用数据库热备份对数据库进行恢复,并验证恢复是否成功。 (8)使用expdp命令导出hum
24、an_resource数据库的ehr模式下的所有数据库对象。 第15章 备份与恢复(4)假设2013-3-12日在数据库中执行了下列操作。略略略(课本可看)(P254)(5)利用闪回查询,查询15:40:10时exercise中的数据(6)利用闪回版本查询,查询15:35:1015:42:10之间sno=100的记录版本信息(7)利用闪回表技术,将exercise表恢复到删除操作进行之前的状态(8)执行“DROP TABLE exercise”语句 然后利用闪回删除技术恢复exercise表(9)将数据库中的闪回日志保留时间设置为3天(4320分钟)(10)利用闪回数据库技术,将数据库恢复到创
25、造表之前的状态set time oncreate table flash_table( id NUMBER PRIMARY KEY, name CHAR(20) );insert into flash_table values(100,jack);commit;insert into flash_table values(200,king);commit;insert into flash_table values(300,john);commit;select * from flash_table;select current_scn from v$database;update flash
26、_table set name=wang where id=100;commit;select * from flash_table;delete from flash_table where id=300;commit;select * from flash_table;alter table flash_table ENABLE ROW MOVEMENT;flashback table flash_table to TIMESTAMP TO_TIMESTAMP(,YYYY-MM-DD HH24:MI:SS);select * from flash_table;flashback table
27、 flash_table to scn ;select * from flash_table;闪回删除create table example( ID NUMBER PRIMARY KEY, NAME CHAR(20) );insert into example values(1,before drop);commit;DROP TABLE example;select OBJECT_NAME,ORIGINAL_NAME,TYPE FROM USER_RECYCLEBIN;flashback table example to before drop rename to new_eample;select * from new_eample;select OBJECT_NAME,ORIGINAL_NAME,TYPE FROM USER_RECYCLEBIN;闪回数据库select SYSDATE from DUAL;select current_scn from v$database;SELECT OLDEST_FLASHBACK_SCN,OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG;SET TIME ON;专心-专注-专业
限制150内