当前位置:文档之家› Oracle实训报告

Oracle实训报告

ORACLE数据库开发实践报告要求1.实践名称:Oracle数据库开发2.实践题目:(1)Oracle数据库的操作(2)小型数据库系统的设计与开发3.实践目的:初步掌握Oracle关系数据库语言;掌握 Oracle的操作与使用;数据库的建立与管理、数据表的建立与操作等;PL/SQL语言的使用与编程。

4.实践内容与结果:4.1 Oracle数据库的操作4.1.1实践操作11、熟悉Oracle运行环境,理解存储管理器、方案管理器和安全管理器的作用及操作过程。

要求:(1).登录到存储管理器中,查看表空间和回滚段中的情况。

(2).登录到方案管理器中,查看SYS方案下的ACCESS$表。

(3).在SQL Plus环境下,键入下面内容,执行并观察结果。

•SQL>SET SERVEROUTPUT ON;•SQL>DECLARE• 2 n1 NUMBER:=18;• 3 n2 NUMBER:=6;• 4 BEGIN• 5 IF n2<=10 THEN• 6 n1:=n1+n2;•7 DBMs_Output.Put_Line(To_Char(n1));•8 END IF;•9 END;•10 /•4.1.2实践操作21、建立数据库(熟悉DBCA工具的使用)2、利用OEM创建新用户SOL语句:CREATE USER "MENG072" PROFILE "DEFAULT"IDENTIFIED BY "m" DEFAULT TABLESPACE "USERS"ACCOUNT UNLOCK;GRANT UNLIMITED TABLESPACE TO "MENG072" GRANT "CONNECT" TO "MENG072";GRANT "DBA" TO "MENG072";3、利用OEM创建Departments表(1)设置一般信息(2)设置约束条件SQL语句:CREATE TABLE "MENG072"."DEPARTMENTS" ("DEPARTMENTID" CHAR(3) NOTNULL, "DEPARTMENGTNAME" CHAR(20) NOT NULL, "NOTE"V ARCHAR2(100) NOT NULL, PRIMARY KEY("DEPARTMENTID")) 4、创建Employees表SOL语句:CREATE TABLE "MENG072"."EMPLOYEES" ("EMPLOYEEID" CHAR(6) NOT NULL, "NAME" CHAR(10) NOT NULL, "BIRTHDAY" DATE NOT NULL, "SEX"NUMBER(1) NOT NULL, "ADDRESS" CHAR(20) NOT NULL, "ZIP"CHAR(6) NOT NULL, "PHONENUMBER" CHAR(12) NOT NULL, "DEPARTMENTID"CHAR(3) NOT NULL, PRIMARY KEY("EMPLOYEEID"))5、创建Salary表SOL语句:CREATE TABLE "MENG072"."SALARY" ("EMPLOYEEID" CHAR(6) NOT NULL, "INCOME"NUMBER(8, 2) NOT NULL, "OUTCOME" NUMBER(8, 2) NOT NULL,PRIMARY KEY("EMPLOYEEID"))6、用PL/SQL语句创建表Departments、表Employees、表Salary:4.1.3实践操作31、用OEM向表Employ、表Departments、表Salary中各插入记录:(1)表Departments插入记录SOL语句:INSERT INTO "DEPARTMENTS" V ALUES ('1' ,'财务部' ,'1' ); INSERT INTO "DEPARTMENTS" V ALUES ('2' ,'人力资源部' ,'2' ); INSERT INTO "DEPARTMENTS" V ALUES ('3' ,'经理办公室' ,'3' ); INSERT INTO "DEPARTMENTS" V ALUES ('4' ,'研发部' ,'4' ); INSERT INTO "DEPARTMENTS" V ALUES ('5' ,'市场部' ,'5' ); (2)表Employ插入记录SOL语句:INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('000001' ,'王林' ,TO_DA TE('23-1月-1966', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'中山路32-1-508' ,'210003' ,'83355668' ,'2' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('010008' ,'伍荣华' ,TO_DA TE('28-3月-1976', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'北京东路100-2' ,'210001' ,'83321321' ,'4' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('020010' ,'王向荣' ,TO_DATE('09-12月-1982', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'四牌楼10-0-108' ,'210006' ,'83792361' ,'1' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('020018' ,'李莉' ,TO_DA TE('30-7月-1976', 'dd-Mon-yyyy HH:MI:SS AM') ,0 ,'中山东路102-2' ,'210002' ,'83413301' ,'1' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('102201' ,'刘明' ,TO_DA TE('02-9月-1965', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'虎踞路100-2' ,'210013' ,'83606608' ,'5' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('102208' ,'朱俊' ,TO_DA TE('10-8月-1979', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'牌楼巷5-3-106' ,'210004' ,'84708817' ,'5' )INSERT INTO "MENG072"."EMPLOYEES" ("EMPLOYEEID" ,"NAME" ,"BIRTHDAY" ,"SEX" ,"ADDRESS" ,"ZIP" ,"PHONENUMBER" , "DEPARTMENTID" ) V ALUES ('108991' ,'忠民' ,TO_DA TE('01-10月-1974', 'dd-Mon-yyyy HH:MI:SS AM') ,1 ,'中山路10-3-105' ,'210003' ,'83346722' ,'3' )(3)表Salary中插入记录SOL语句:INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('000001' ,2100.8 ,123.09 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('010008' ,1582.62 ,88.03 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('102201' ,2569.88 ,185.65 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('108991' ,3259.98 ,281.52 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('020010' ,2860.0 ,198.0 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('020018' ,2347.68 ,180.0 )INSERT INTO "MENG072"."SALARY" ("EMPLOYEEID" ,"INCOME" ,"OUTCOME" ) V ALUES ('102208' ,1980.0 ,100.0 )2、用PL/SOL语句向表Employ、表Departments、表Salary中插入记录:4.1.4实践操作41、建立索引:2、实现域完整性:注:该同学此题完成有误,下面给出另一同学的正确解答为数据库中的employees表的phonenumber列建立check约束:3、实现实体完整性:(1)为表Departments设置主键DepartmentID:(2)为表Departments的DepartmentName建立唯一性索引:4实现参照完整性:4.1.5实践操作51、SELECT语句的基本使用:(1)查询每个雇员的所有数据:(2)查询每个雇员的地址和电话:(3)查询EmployeeID为000000的雇员的地址和电话:(4)查询Employees表中女雇员的地址和电话;(5)计算每个雇员的实际收入:(6)找出所有姓王的雇员的部门号:(7)找出所有收入在2000~5000元之间的雇员号码:2 子查询的使用(1)查找在财务部工作的雇员的情况:(2)查找财务部年龄不低于研发部雇员年龄的雇员的姓名:(3)查找比所有财务部的雇员收入都高的雇员的姓名:3.连接查询的使用(1)查询每个雇员的情况及其薪水的情况:(2)查找财务部收入在2200元以上的雇员姓名及其薪水情况:4.数据汇总(1)求财务部雇员的平均水平:(2)求财务部雇员的平均实际收入:(3)求财务部雇员的总人数:5.GROUP BY、ORDER BY 子句的使用(1)求各部门的雇员数:(2)将各雇员的情况按收入由低到高排列:6.视图(1)创建视图——限制查看雇员的某些情况:各部门经理只能查找本部门雇员的薪水情况:(2)使用视图查询财务部雇员的信息:查询财务部雇员薪水情况:向表EMPLOYEES中插入一条记录:从经理办公室转到市场部:从表EMPLOYEES中删除:4.1.6实践操作61.条件结构的使用例5.52.循环结构的使用例5.92.选择和跳转语句例5.134.自定义函数的使用例5.27例5.284.1.7实践操作71.创建触发器(1)修改DEPARTMENTS表中的DEPARTMENTID字段值(2)删除DEPARTMENTS表中一条记录的同时删除该记录DEPARTMENTID字段在EMPLOYEES表中对应的记录2.创建存储过程(1)添加职员记录的存储过程:(2)修改职员记录的存储过程;(3)删除职员记录的存储过程:3.调用存储过程4.1.8实践操作8 1.创建用户2.创建角色3.创建概要文件5.实践小结:在实训之前,我对Oracle一无所知,后来经过老师课上耐心细致的讲解,我对Oracle 渐渐有了较为清晰的认识。

相关主题