Oracle实验报告2答案

合集下载

oracle实验报告及答案 用户、权限安全

oracle实验报告及答案   用户、权限安全

实验三用户、权限安全班级:座号:姓名:时间:一、实验目的1.创建用户2.创建角色3.使用GRANT和REVOKE语句授予和撤销对象权限二、实验设备一台PC机,widows操作系统,oracle 10g三、实验内容1. 使用sys身份连接到数据库。

2.创建一个用户TEMPUSER,其口令为oracle,默认表空间为USERS,对表空间没有配额限制,临时表空间为TEMP。

3. 创建一个用户配置文件TEMPPROFILE,包含的资源及口令限制如下:该用户最多可以建立3个并发的会话连接用户执行语句使用的CPU最长时间为20分钟空闲时间超过15分钟后,断开与用户的连接限制用户每次调用SQL语句时,能够读取的数据库块数200限制用户在登录到Oracle数据库时允许失败的次数24. 为用户TEMPUSER指定配置文件5. 向用户授予连接数据库系统权限。

6.向用户授予对对象HR.JOBS的SELECT权限,并以用户TEMPUSER连接到数据库,以查询jobs表。

7.以sys身份登录,撤销向用户TEMPUSER授予的系统权限,向用户授予CONNECT,resource角色。

8. 以tempuser身份登录,在exer_tabspace表空间创建表customer(x number)。

四、实验步骤1.使用sys身份连接到数据库。

Connect sys/oracle as sysdba;(查看表空间信息SELECT TABLESPACE_NAME FROM DBA_TABLESPACES;)2. 创建一个用户TEMPUSERCreate user tempuser identified by oracle default tablespace USERS temporary tablespace temp quota unlimited on users;3.创建一个用户配置文件TEMPPROFILE4.为用户TEMPUSER指定配置文件Alter user tempuser profile tempprfile;5向用户授予连接数据库系统权限6、ALTER SYSTEM SET RESOURCE_LIMIT=TRUE SCOPE=BOTH;(启用资源限制,参数立即生效)(再开第二个窗口,第三个窗口,第四个窗口都用TEMPUSER/ORACLE登陆,看看会发生什么情况)7. 向用户授予对对象“HR.JOBS”的SELECT权限,并以用户TEMPUSER连接到数据库,以查询“JOBS”表。

Oracle实验报告及答案 数据库管理与工具使用

Oracle实验报告及答案  数据库管理与工具使用

实验一 Oracle数据库管理与工具使用班级:座号:姓名:时间:一、【实验目的】1.掌握Oracle的启动、关闭、连接和管理初始化参数2.熟悉oem和SQL*Plus的使用3.了解用户和模式的概念,并查询hr模式表的数据二、【实验设备】一台PC机,widows xp操作系统,oracle 10g或11g三、【实验内容】1.启动和关闭window操作系统的Oracle服务2.通过三种方式访问数据库3.使用SQL*Plus启动和关闭Oracle数据库4.使用em和SQL*Plus解锁hr模式,并使用SQL*Plus编写查询该模式中表的SQL命令5.使用em和SQL*Plus显示和设置初始化参数文件四、【实验步骤】1 启动服务(开始,设置,控制面板,管理工具,服务)2通过三种方式连接数据库:方法一:在运行窗口中输入CMD命令,然后在窗口中输入SQLPlus命令以启动SQL*Plus工具方法二:开始/程序/Oracle - OraDb10g_home1/SQL Plus打开登录界面,然后输入相应的用户名称和登录密码。

方法三:打开IE,输入本机IP:5560/isqlplus 或者localhost:5560/isqlplus,启动Oracle Enterprise Manager(OEM),以图形话方式对数据库进行操作。

Select * from hr.employees;3 使用SQL*Plus用sys用户关闭Oracle数据库4通过三种方式启动数据库:1)startup nomount;2) alter database mount;3)ALTER DATABASE OPEN;5确认数据库状态:Select instance_name,status from v$instance;6 解锁hr用户7使用hr用户连接sqlplus,Select * from employees;8用SQL*Plus显示所有初始化参数SHOW PARAMETER;五、【实验小结】通过本次实验学会通过oem和SQL*Plus与数据库建立连接,启动、关闭数据库。

《oracle 10g 数据库基础教程》实验报告

《oracle 10g 数据库基础教程》实验报告

《oracle 10g 数据库基础教程》实验报告实验名称:金融数据库技术实验二实验目的:远程登录数据库,使用OEM、SQL等方法创建表,熟悉创建语句实验内容:1、远程连接数据库。

2、用OEM管理表。

3、用SQL*Plus管理表。

4、Oracle数据操纵和查询实验步骤:远程登录显示用户创建用户要连接远程的网络数据库,先要在客户端上设定被连接的数据库服务器的Net服务名。

在客户端启动Net Configuration Assistant选择“本地Net服务名配置”。

添加服务器的IP可以创建具有个人特色的名字回到OEM登录界面配置完毕后回到OEM,进行表的创建等。

⏹以管理员身份登录OEM,为用户scott创建一个名称为employee的表,指定表空间example。

⏹该表包含以下属性:eno,ename,eage,sex,salary。

为其设置合适的数据类型和大小。

⏹为各属性设置如下约束:eno为主键,约束名称为T_PK。

在“管理”中寻找“表”进行创建,选择创建在方案上选择用户名,对象名为要创建的表名添加列名,添加束缚语句等。

在OEM界面完成表的创建和添加约束条件后,在SQL中查看表格情况⏹在sql plus命令行界面创建和管理表,并写出相应的SQL语句。

⏹创建一个表student,指定表空间为STU,占用空间大小为10M。

⏹表中的各列及约束仿照OEM表设置。

用SQL语句为表添加phone和birthdates属性,并为phone列添加unique约束。

输入信息:向student表中插入一行记录,姓名为serena,学号为5,其余信息与名为王霞的学生一样。

利用select子查询语句实现。

将学生李晨的phone改为139,birthdates改为22-6月-92。

将赵勇性别改为M。

实验总结:今天学习1、远程连接数据库。

2、用OEM管理表。

3、用SQL*Plus管理表。

4、Oracle 数据操纵和查询。

远程连接的难度在于,要分清楚服务器与客户端之间的差别。

《Oracle数据库》实验报告

《Oracle数据库》实验报告

实验二Oracle数据库开发环境下PL/SQL编程(2学时)【实验目的】(1)掌握PL/SQL 的基本使用方法。

(2)在SQL*PLUS环境下运行PL/SQL的简单程序。

(3)应用PL/SQL 解决实际问题【实验内容与步骤】一、实验内容:1、用PL/SQL实现:输入eno的值,显示emp表中对应记录的内容。

2、用PL/SQL完成:读入三个数,计算并输出它们的平均值及三个数的乘积。

3、对职工表emp中的雇员SCOTT提高奖金,若工种为MANAGER,则奖金提高其原来的20%;若工种为SALESMAN,则奖金提高其原来的15%;若工种为ANALYST,则奖金提高其原来的10%,其它都按原来的7%提高。

4、用PL/SQL块实现下列操作公司为每个职工增加奖金:若职工属于30号部门,则增加$150;若职工属于20号部门,则增加$250;若职工属于10号部门,则增加$350。

(提示:游标请自行阅读相关内容)DECLAREaddcomm m%type;CURSOR emp_cursor IS select deptno from emp;BEGINFOR emprec IN emp_cursor LOOPIF emprec.deptno=30 THEN addcomm:=150;ELSIF emprec.deptno=20 THEN addcomm:=250;ELSIF emprec.deptno=10 THEN addcomm:=350;END IF;Update empset comm=comm+ addcomm where deptno= emprec.deptno;END LOOP;COMMIT WORK;END;实验三PL/SQL触发器和存储过程(2学时)【实验目的】(1)了解触发器的类型。

(2)掌握PL/SQL触发器的使用方法。

(3)了解存储过程的使用方法。

(4)掌握存储过程的使用方法。

【实验内容】实验内容:1、编写一个数据库触发器,当任何时候某个部门从dept表中删除时,该触发器将从emp 表中删除该部门的所有雇员。

《Oracle数据库应用与实践》课后习题参考答案

《Oracle数据库应用与实践》课后习题参考答案

第 5 章 Oracle 模式对象
一、填空题
1. 字段级约束 表约束
2. NOT NULL 约束 UNIQUE 约束 PRIMARY KEY 约束

3. CREATE TABLE
CREATE ANY TABLE
4. UNIQUE PRIMARY KEY CHECK
5. 合并索引 重建索引
6. user_updatable_columns
一、 填空题 1. 数据挖掘 隐含的 未知的 2. API-ODM Java API ODM DBMS_DM PL/SQL API
3. Clustering Association Feature Extraction
Oracle 数据库应用与实践
2、某 cc 表数据如下: c1 c2 -------------1西 1安 1的 2天 2气
Oracle 数据库应用与实践
3好 …… 转换为 1 西安的 2 天气 3好 要求:不能改变表结构及数据内容,仅在最后通过 SELECT 显示出这个查询结果
代码为: create or replace function x return varchar2 is type t_array is table of number index by binary_integer; type tarray is table of varchar2(10) index by binary_integer; ta t_array; tar tarray; re varchar2(10); n number; na varchar2(10); begin select id bulk collect into ta from (select id,name from xx order by id) group by id; for i in st loop dbms_output.put(ta(i)||' '); select name bulk collect into tar from xx where id=ta(i); for i in st loop dbms_output.put(tar(i)); end loop; dbms_output.put_line(' '); end loop; return re; end;

Oracle数据库实验报告1—2

Oracle数据库实验报告1—2

《数据库原理及应用-Oracle》实验报告姓名:李奕学号:12600120班级:计非121班实验一:Oracle平台下基本SQL语言的应用1、列出至少有一个员工的全部部门及人数。

SQL> select deptno ,count(ename) from emp group by deptno having count(ename)>1;2、列出薪金比“SMITH”多的全部员工。

SQL> select ename from emp where sal>ALL(select sal from emp where ename='SMITH');3、列出全部员工的姓名及其直接上级的姓名SQL> SELECT 员工.ENAME,上级.ENAME FROM EMP 员工,emp 上级 WHERE 员工.MGR=上级.EMPNO;4、列出受雇日期早于其直接上级的全部员工。

edate;5、列出部门名称和这些部门的员工信息,同时列出那些没有员工的部门。

select d.dname,ename,empno,job,hiredate,sal from emp e right join dept d on e.deptno=d.deptno;6、列出全部“CLERK”(做事员)的姓名及其部门名称。

select e.ename,d.dname from emp e,dept d wheree.deptno=d.deptno and e.job='CLERK';7、列出最低薪金大于1500的种种工作。

SQL> select job from emp group by job having min(sal)>1500;8、列出在部分门“SALES”(贩卖部)做事的员工的姓名,假定不知道贩卖部的部门编号。

select ename from emp where deptno=(select deptno from dept where dname='SALES');o = d.deptno AND d.dname='SALES';SELECT e.ename FROM emp e JOIN dept d ON e.deptno = d.deptno AND d.dname='SALES';9、列出薪金高于公司平均薪金的全部员工。

《Oracle数据库》实验报告二(2)

《Oracle数据库》实验报告二(2)

广东金融学院实验报告课程名称:Oracle数据库1四、实验步骤及结果(包含简要的实验步骤流程、结论陈述)1. 创建表空间 stu_tbsSQL>create tablespace stu_tbs2 datafile 'c:\finance_db\' size 25m online;创建用户 stuuser5SQL>create user stuuser5_sql identified by user2sql;SQL>alter user stuuser5_sql account lock;查看“stuuser+学号_sql”用户的信息SQL>select * from all_users;3查看该用户验证的方式DBA_USERS 数据字典中查看“stuuser+学号_sql”用户的默认表空间和临时表空间用企业管理器,修改“stuuser+学号”用户,验证方式为外部用户解锁,并修改密码SQL>alter user stuuser2_sql account unlock;SQL>alter user stuuser2_sql identified by sql2user;5授予“stuuser+学号_sql”用户“SYSOPER”系统权限SQL>grant sysoper to stuuser5_sql;sqlplus 收回用户在“SYSTEM”方案中对“help”表的查看、修改、删除等对象权限SQL>revoke select,alter,delete on from stuuser2;用 Ssqlplus 收回用户的“SYSOPER”系统权限SQL>revoke sysoper from stuuser2_sql;利用企业管理器查看所有表的字段信息和约束信息SQL>select * from DBA_TAB_COLUMNS;表数据编辑(用“stuuser+学号_sql”用户完成)①用“stuuser+学号”用户完成对“stuuser+学号_sql”用户的相关授权SQL> grant create session, create table to stuser5 with admin option;SQL> conn stuser5/orace;SQL> grant create session,create table to stuuser5_sql;对表中数据的编辑,包括添加、修改和删除SQL> create table Customer2 (CustomerNumber NUMBER(10,0) not null constraint pk primary key,3 CustomerName VARCHAR(10) not null,4 CustomerSex NCHAR(1) not null,5 CustomerIDCard CHAR(18) not null)SQL>insert into2 Customer (CustomerNumber, CustomerName, CustomerSex, CustomerIDCard)3 values('1','杨虹','女', '23216');SQL>update Customer set CustomerSex='女',CustomerName= '赵敏'2 where CustomerNumber=2;SQL>delete from Customer where CustomerName like '杨%';7利用 SQL*Plus 或 iSQL*Plus 实现对表中数据的各种实用性查询SQL> select * from Customer where CustomerNumber=19。

ORACLE数据库测试2及答案

ORACLE数据库测试2及答案

1、表中的约束有哪些?请举例说明。

答:①primary key:学生表的学号②foreign key:成绩表的学号③check:性别in(‘男’,’女’)④not null:学生表的姓名⑤default:订购单订购日期为系统时间⑥unique:学生表中若学号为主键,ID号用unique2、引用索引的原则是什么?P84答:①在表中插入数据后创建索引②索引正确的表和列③合理安排索引列④限制表中索引的数量⑤制定索引数据块空间⑥根据索引大小设置存储参数。

3、简要说明用户、角色和权限之间的关系。

P172答:角色是一组权限,可授予用户或其他角色。

可利用角色来管理数据库权限,可将权限添加到角色中,然后将角色授予用户。

用户可使该角色起作用,并实施角色授予的权限。

一个角色包含所有授予角色的权限及授予它的其他角色的全部权限。

4、oracle的逻辑结构是如何组织的?答:作业中有二、用PL/SQL编程,计算S=1/2+1/4+1/8+…+1/2ⁿ,S精确到万分之一。

解:declaren number:=2;S number:=0;beginloopS:=S+1/n;n:=n*2;if 1-S<=(1/10000) thendbms_output.put_line(S);exit;end if;end loop;end;三、编写存储过程,求指定某门课程(课程名)的平均分数。

解:create or replace procedure proc(kcm in carchar2)avg1 number;beginselect AVG(成绩) as 平均分into avg1 from CJB where 课程号in (select 课程号from KCB where 课程名=kcm and rownum=1);dbms_output.put_line(avg1);end;四、编写触发器,向成绩表中插入一条记录,检查学生是否在学生表中存在,若不存在,则取消该操作。

Oracle实验报告2标准答案

Oracle实验报告2标准答案
(5)创建一个查询显示工资大于2850美元的姓名及工资。将该查询保存成脚本文件p2q1.sql,并执行该文件。
(6)修改脚本文件p2q1.sqll文件重新保存该查询。
(7)修改文件p2q2.sql,显示在10和30部门工作并且工资大于1500美元的雇员的姓名和工资,列标题显示为Employee和MonthlySalary,最后以p2q3.sql重新保存该文件,返回查询结果。
《Oracle数据库技术》
实验指导书2
基本SELECT、WHERE和ORDERBY子句的使用ﻬ
实验要求
1)掌握SQL*PLUS的基本使用.
2)掌握SELECT语句的简单用法.
3)掌握WHERE子句的用法。
4)掌握ORDER BY子句的用法。
实验步骤
(1)登录到SQL*Plus,初始用户名:SCOTT,口令为TIGER。
6.显示在10号和30号部门工作的雇员的姓名及其部门编号,并以字母顺序排列。
7.显示所有受雇于1982年的雇员的姓名和受雇日期。
8.显示没有上级管理员的雇员的姓名及其工作。
9.显示能挣得奖金的雇员的姓名、工资、奖金,并以工资和奖金降序排列。
10.显示姓名中第三个字母为A的雇员的姓名。
11.显示姓名中两次出现字母L并且在30部门工作或者其管理员编号是7782的雇员的姓名。
12.显示工作为clerk或analyst并且工资不等于1000、3000、5000的雇员的姓名、工作及工资。
SQL>SELECT empno,ename
2salary*12ANNUALSLARY
3FROMemp;
3.创建一个查询EMP表中检索出不重复的工作名称
4.创建一个查询显示雇员编号为7566的雇员的姓名和部门编号。

oracle数据库实用教程第二版答案

oracle数据库实用教程第二版答案

oracle数据库实用教程第二版答案oracle数据库实用教程第二版答案【篇一:oracle 11g(钱慎一)课后习题答案】若关系的某一属性组的值能唯一地标识一个元组,我们称之为( b )。

a、主码b、候选码c、外码d、联系2. 以下不属于数据库模型的三要素的是( c )。

a、数据结构b、数据操作c、数据控制d、完整性约束3. 以下对关系性质的描述中,哪个是错误的?( b )a、关系中每个属性值都是不可分解的b、关系中允许出现相同的元组c、定义关系模式时可随意指定属性的排列次序d、关系中元组的排列次序可以任意交换二、填空题1. 数据管理发展的三个阶段是人工管理、文件管理和数据库管理。

2. 数据库系统的三级模式包括逻辑数据模型(逻辑模型)、逻辑数据模型(概念模型)、物理数据模型(物理模型)。

三、思考题1. 数据库管理系统的主要功能有哪些?1)数据定义功能。

dbms提供相应数据语言来定义(ddl)数据库结构,它们是刻画数据库框架,并被保存在数据字典中。

2)数据存取功能。

dbms提供数据操纵语言(dml),实现对数据库数据的基本存取操作:检索,插入,修改和删除。

3)数据库运行管理功能。

dbms提供数据控制功能,即是数据的安全性、完整性和并发控制等对数据库运行进行有效地控制和管理,以确保数据正确有效。

4)数据库的建立和维护功能。

包括数据库初始数据的装入,数据库的转储、恢复、重组织,系统性能监视、分析等功能。

5)数据库的传输。

dbms提供处理数据的传输,实现用户程序与dbms之间的通信,通常与操作系统协调完成。

2. 思考关系规范化的过程。

答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。

一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。

3. 思考数据库设计的步骤。

答:1需求分析、2概念设计阶段、3逻辑结构设计阶段、4数据库物理结构设计阶段、5数据库实施阶段、6数据库运行和维护阶段。

Oracle实验报告二

Oracle实验报告二

实验报告二课程名称: Oracle10数据库 实验项目:数据库物理和逻辑储存结构操作 指导教师: 李庆风 实验位置: 计算中心软件工程实验室姓 名: 叶贝贝 学 号: 10401010447 班 级: 计科104 日 期: 2013-3-12一、实验目的掌握Oracle10g 数据库物理结构的操作,学会数据文件的管理,利用SQL*Plus 对数据文件的创建、修改等操作,学会控制文件的创建、备份、删除等操作,学会重做日志文件。

掌握Oracle10g 数据库逻辑结构的操作,学会表空间的操作,利用SQL*Plus 对表文件创建、修改、删除等操作。

二、实验环境安装有Oracle10g 数据库软件等的计算机。

三、实验内容1.Oracle10g 数据库数据文件管理(创建、删除等操作) 2.控制文件操作(创建、备份、删除等操作) 3.重做日志文件4.表控件操作(创建、修改、删除等操作)四、实验操作实验内容一:数据文件操作1启动SQL*Plus2创建Oracle10g 数据库数据文件 创建5MB 的users02.dbf创建5MB 的temp02.dbf3.修改数据文件创建users03.dbf并设置为自动增长512k空间最大50M修改users02.dbf设置为自动增长512k空间最大50M取消users02.dbf的自动增长将users02.dbf的空间设置为8M4.删除数据文件删除users03.dbf数据文件删除temp02.dbf数据文件实验内容操作二:控制文件的创建检查数据库是否打开三个都可以打开,数据库处于打开状态关闭数据库转换工作环境创建新的控制文件恢复数据库正常打开数据库指定resetlogs方式打开实验内容三:重做日志文件1.添加重做日志文件组2.添加重做日志成员3.删除重做日志成员4.删除重做日志文件组实验内容四:表空间操作1.创建永久表空间2.创建临时表空间3修改表空间4.删除表空间五、实验心得小结在本次实验中,让我学会了数据文件的创建、删除等操作,控制文件的操作,对日志文件和表空间的操作都实践了一次,实验课上时间有限,总体感觉仍须不断实践,熟练掌握。

Oracle数据库-作业2-答案

Oracle数据库-作业2-答案

Oracle数据库-作业2-答案第二次书面作业答案(作业在2013.5.15之前交,使用学院统一的作业封面,题目可以打印,答题内容必须手写)一、填空题1.PL/SQL程序块主要包括3个主要部分:声明部分、执行部分和异常处理部分。

2.使用显式游标主要包括4个步骤:声明游标、打开游标、提取数据、关闭游标。

3.在PL/SQL中,如果SELECT语句没有返回任何记录,则会引发NO_DATA_FOUND 异常。

4.查看操作在数据表中所影响的行数,可通过游标的%ROWCOUNT 属性实现。

5.在下面程序的空白处填写适当的代码,使该函数可以获取指定编号的员工薪金。

CREATE OR REPLACE FUNCTION get_sal(P_ID varchar2) return number isv_sal number;beginselect sal into v_sal from emp where empno= P_ID ;returen v_sal;exceptionwhen no_data_found thendbms_output.put_line('无法找到该编号的员工!');when others thendDms_output.put_line('发生其他错误!');end get_sal;6.ROWID实际上保存的是记录的物理地址,因此通过ROWID 来访问记录可以获得最快的访问速度。

7.完成下面的语句,使其可以为EMPLOYEES表的EMPNO列添加一个名为PK_EMPNO的主键约束。

ALTER TABLE EMPLOYEES ADD CONSTRAINT PK_EMPNOPRIMARY KEY EMPNO ;8.B树索引可以是惟一的或者不惟一的,惟一的B树索引可以保证索引列上不会有重复的值。

9.Oracle数据库提供的对表或索引的分区方法有5种,分别为:范围分区、散列分区、列表分区、组合范围散列分区和组合范围列表分区。

oracle实验内容2(共40题)

oracle实验内容2(共40题)

Part 11.Write a query to display the current date. Label the column Date.select to_char(sysdate,'year-mon-day')“D ate”from dual2. The HR department needs a report to display the employee number, last name, salary, and salary increased by 15.5% (expressed as a whole number) for each employee. Label the column New Salary. Place your SQL statement in a text file named lab_03_02.sql.select employee_id,last_name,salary,salary*1.155 new_salaryfrom employees3. Run your query in the file lab_03_02.sql.4. Modify your query lab_03_02.sql to add a column that subtracts the old salary fromthe new salary. Label the column Increase. Save the contents of the file as lab_03_04.sql. Run the revised query.select employee_id,last_name,salary,salary*1.155new_salary,salary*0.155 increasefrom employees……5.Write a query that displays the last name (with the first letter uppercase and all other letterslowercase) and the length of the last name for all employees whose name starts with the letters J, A, or M. Give each column an appropriate label. Sort the results by the employees’ last names.select last_name,length(last_name) lengthfrom employeeswhere last_name like'A%'or last_name like'J%'or last_name like'M%' order by last_nameRewrite the query so that the user is prompted to enter a letter that starts the last name. For example, if the user enters H when prompted for a letter, then the output should show all employees whose last name starts with the letter H.6. The HR department wants to find the length of employment for each employee. For each employee, display the last name and calculate the number of months between today and the date on which the employee was hired. Label the column MONTHS_WORKED. Order your results by the number of months employed. Round the number of months up to the closest whole number.Note: Your results will differ.select last_name,round(months_between(sysdate,hire_date))"MONTHS_WORKED"from employeesorder by hire_date desc7. Create a report that produces the following for each employee:<employee last name> earns <salary> monthly but wants <3 times salary>. Label the column Dream Salaries.select last_name||' earns'||to_char(salary,'$999,999.99')||' monthly but wants'||to_char(3*salary,'$999,999.99')from employees8.Create a query to display the last name and salary for all employees. Format the salary to be15 characters long, left-padded with the $ symbol. Label the column SALARY.select last_name,lpad(salary,15,'$')"SALARY"from employees9.Display ea ch employee’s last name, hire date, and salary review date, which is the firstMonday after six months of service. Label the column REVIEW. Format the dates to appear in the format similar to “Monday, the Thirty-First of July, 2000.”Select last_name,to_char(hire_date,'dd-mm-yy')"hire_date",to_char(next_day(add_months(hire_date,’星期一'),'day,"the" ddspth "of" month,yyyy') "REVIEW"from employees10.Display the last name, hire date, and day of the week on which the employee started. Labelthe column DAY. Order the results by the day of the week, starting with Monday.select last_name,hire_date,to_char(hire_date,'day')"DAY"from employeesorder by to_char(hire_date-1,'d')11.Create a query that displays the employees’ last names and commission amounts. If anemployee does not earn commission, show “No Commission.” Label the column COMM. Select last_name,nvl(to_char(commission_pct),' No Commission')"COMM"From employees12.Create a query that displays the first eight characters of the employees’ last names andindicates the amounts of their salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in descending order of salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.Select rpad(substr(last_name,1,8),8)|| lpad(' ',salary/1000,'*')from employeesorder by salary desc13. Using the DECODE function, write a query that displays the grade of all employees based on the value of the column JOB_ID, using the following data:Job GradeAD_PRES AST_MAN BIT_PROG CSA_REP DST_CLERK ENone of the above 0select job_id,decode(job_id,'AD_PRES','A','ST_MAN','B','IT_PROG','C','SA_REP','D','ST_CLERK','E',0)"GRA"from employees14. Rewrite the statement in the preceding exercise using the CASE syntax.select job_id,case job_id when'AD_PRES'then'A'when'ST_MAN'then'B'when'IT_PROG'then'C'when'SA_REP'then'D'when'ST_CLERK'then'E'else'0'end"GRA"from employees15.Group functions work across many rows to produce one result per group.True/False T16.Group functions includee nulls in calculations.True/False F17.The WHERE clause restricts rows before inclusion in a group calculation.True/False TThe HR department needs the following reports:18.Find the highest, lowest, sum, and average salary of all employees. Label the columns Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest whole number. Place your SQL statement in a text file named lab_04_04.sql.select max(salary)"maximum",min(salary)"minimum",sum(salary) "Sum", round(avg(salary))"Average"from employees19,Modify the query in lab_04_04.sql to display the minimum, maximum, sum, and average salary for each job type. Resave lab_04_04.sql as lab_04_05.sql. Run the statement in lab_04_05.sql.select job_id,max(salary)"maximum",min(salary)"minimum",sum(salary)"Sum", round(avg(salary))"Average"from employeesgroup by job_id20.Write a query to display the number of people with the same job.select job_id,count(*)from employeesgroup by job_id21. Determine the number of managers without listing them. Label the column Number of Managers. Hint: Use the MANAGER_ID column to determine the number of managers.select count(distinct manager_id) "Number of Managers"from employees22.Find the difference between the highest and lowest salaries. Label the column DIFFERENCE. select max(salary)-min(salary)"Difference"from employees23.Create a report to display the manager number and the salary of the lowest-paid employeefor that manager. Exclude anyone whose manager is not known. Exclude any groups where the minimum salary is $6,000 or less. Sort the output in descending order of salary.select manager_id,min(salary)from employeeswhere manager_id is not nullgroup by manager_idhaving min(salary)>600024.Create a query to display the total number of employees and, of that total, the number of employees hired in 1995, 1996, 1997, and 1998. Create appropriate column headings.select count(*) total,sum(decode(to_char(hire_date,'yyyy'),'1995',1,0))"1995",sum(decode(to_char(hire_date,'yyyy'),'1996',1,0))"1996",sum(decode(to_char(hire_date,'yyyy'),'1997',1,0))"1997",sum(decode(to_char(hire_date,'yyyy'),'1998',1,0))"1998"from employees25. Create a matrix query to display the job, the salary for that job based on department number, and the total salary for that job, for departments 20, 50, 80, and 90, giving each column an appropriate heading.select job_id "JOB",sum(decode(department_id,20,salary,0))"Dept 20",sum(decode(department_id,50,salary,0))"Dept 50",sum(decode(department_id,80,salary,0))"Dept 80",sum(decode(department_id,90,salary,0))"Dept 90",sum(salary)"Total" from employeesgroup by job_id26.Write a query for the HR department to produce the addresses of all the departments. Use the LOCATIONS and COUNTRIES tables. Show the location ID, street address, city, state or province, and country in the output. Use a NATURAL JOIN to produce the results.select LOCATION_ID,STREET_ADDRESS,CITY,STATE_PROVINCE,COUNTRY_NAMEfrom LOCATIONS natural join COUNTRIES27.The HR department needs a report of all employees. Write a query to display the last name, department number, and department name for all employees.select last_name,department_id,department_namefrom employees natural join departments28.The HR department needs a report of employees in Toronto. Display the last name, job, department number, and department name for all employees who work in Toronto.select last_name,job_id,department_id,department_name,cityfrom employees join departments using(department_id)join locations using(location_id)where city='Toronto'29.Create a report to display employees’ last name and employee number along with theirmanager’s last name and manager number. Label the columns Em ployee, Emp#, Manager,and Mgr#, respectively. Place your SQL statement in a text file named lab_05_04.sql. Select st_name,e1.employee_id,st_name,e1.manager_idFrom employees e1 join employees e2 on e1.manager_id=e2.employee_id30.Modify lab_05_04.sql to display all employees including King, who has no manager. Orderthe results by the employee number. Place your SQL statement in a text file named lab_05_05.sql. Run the query in lab_05_05.sql.Select st_name,e1.employee_id,st_name,e1.manager_idFrom employees e1 left join employees e2 on e1.manager_id=e2.employee_idOrder by e1.employee_id31.Create a report for the HR department that displays employee last names, departmentnumbers, and all the employees who work in the same department as a given employee.Give each column an appropriate label. Save the script to a file named lab_05_06.sqlselect e1.department_id,st_name EMPLOYEE,st_name COLLEAGUE from employees e1 join employees e2 on e1.DEPARTMENT_ID =e2.DEPARTMENT_ID and ST_NAME<>ST_NAMEorder by e1.department_id32.The HR department needs a report on job grades and salaries. To familiarize yourself withthe JOB_GRADES table, first show the structure of the table. Then create a query that displays the name, job, department name, salary, and grade for all employees.select last_name,job_id,department_name,salary,GRADE_LEVELfrom employees join departments using(department_id)join JOB_GRADES on salary>LOWEST_SAL and salary<HIGHEST_SAL33.The HR department wants to determine the names of all employees who were hired afterDavies. Create a query to display the name and hire date of any employee hired after employee Davies.select last_name,hire_datefrom employeeswhere hire_date>(select hire_date from employees where last_name ='Davies')34.The HR department needs to find the names and hire dates for all employees who werehired before their managers, along with their managers’ names and hire dates. Save the script to a file named lab5_09.sql.select ST_NAME,e1.HIRE_DATE,st_name,e2.hire_datefrom employees e1 join employees e2 on e1.MANAGER_ID = e2.employee_idwhere e1.hire_date<e2.hire_date35.The HR department needs a query that prompts the user for an employee last name. Thequery then displays the last name and hire date of any employee in the same department as the employee whose name they supply (excluding that employee). For example, if the user enters Zlotkey, find all employees who work with Zlotkey (excluding Zlotkey).select last_name,hire_datefrom employeeswhere department_id =(select department_idfrom employeeswhere last_name='&name')and last_name!='&name'36 .Create a report that displays the employee number, last name, and salary of all employees who earn more than the average salary. Sort the results in order of ascending salary.select department_id,last_name,salaryfrom employeeswhere salary>(select avg(salary)from employees)order by salary37.Write a query that displays the employee number and last name of all employees who work in a department with any employee whose last name contains a u. Place your SQL statement in a text file named lab_06_03.sql. Run your query.select employee_id,last_namefrom employeeswhere department_id in(select department_idfrom employeeswhere last_name like'%u%')38.The HR department needs a report that displays the last name, department number, and job ID of all employees whose department location ID is 1700.select last_name,department_id,job_idfrom employees join departments using(department_id)join locations using(LOCATION_ID )where LOCATION_ID =1700order by department_idModify the query so that the user is prompted for a location ID. Save this to a file named lab_06_04.sql.39.Create a report for HR that displays the last name and salary of every employee who reportsto King.select last_name,salaryfrom employeeswhere manager_id =(select employee_idfrom employeeswhere last_name ='King')40. Create a report for HR that displays the department number, last name, and job ID for every employee in the Executive department.select department_id,last_name,job_idfrom employees join departments using(department_id)where department_name='Executive'If you have time, complete the following exercise:40.Modify the query in lab_06_03.sql to display the employee number, last name, and salary ofall employees who earn more than the average salary and who work in a department withany employee whose last name contains a u. Resave lab_06_03.sql as lab_06_07.sql. Run the statement in lab_06_07.sql.select employee_id,last_name,salaryfrom employeeswhere department_id in(select department_idfrom employeeswhere last_name like'%u%')and salary >(select avg(salary)from employees)。

oracle实验二

oracle实验二

oracle实验⼆电信学院《oracle数据库技术及应⽤》实验报告<⼆>实验名称:管理参数⽂件及控制⽂件成绩:专业班级:姓名:学号:实验⽇期:2018 年 3 ⽉ 29 ⽇⼀、实验报告填写要求按顺序写出相应的命令,列出重要执⾏结果的截图,截图的宽度统⼀为10cm⼆、实验⽬的1、通过查看参数⽂件的内容,理解参数⽂件的作⽤;(必)2、掌握参数⽂件的创建⽅法pfile及spfile;(必)3、掌握查看控制⽂件内容的⽅法及备份控制⽂件的⽅法;(必)4、掌握多元化控制⽂件的⽅法;(必)5、掌握重建控制⽂件的⽅法;(必)6、掌握字符串、数字、⽇期和null的常⽤函数(选)7、掌握条件函数(选)三、实验内容1、查看参数⽂件内容:两种⽅式;(10分)⾸先,默认是没有pfile参数⽂件的。

需要create pfile from spfile;创建⼀个pfile参数⽂件。

pfile是⼀个⽂本⽂件,可以直接使⽤操作系统编辑器直接打开查看spfile是⼀个⼆进制⽂件,由oracle server管理,必须在sqlplus下使⽤命令查看。

show parmameter可以查看当前数据库实例启动时所⽤的参数⽂件(包括pfile和spfile)SQL> startup; #默认以spfile启动时SQL>show parameter;SQL> shutdown immediate; #关闭数据库,准备以pfile参数⽂件启动SQL> startup pfile=’ C:\oracle\ora92\database\INITora9i.ORA’; #当以pfile为启动时的参数⽂件时SQL>show parameter; #格式化⽅式查看pfile内容2、在D:\创建⼀个spfile,⼀个pfile;(10分)#在D盘根⽬录创建spfile,⽂件名为”SPFILEOra9i02.ora”SQL> create spfile=’D:\SPFILEOra9i02.ora’ from pfile;注:如果未指定spfile⽂件位置和⽂件名,将在默认位置创建,但是此时创建时应该处于数据库实例关闭的情况下,或者启动数据库实例时使⽤的是pfile参数⽂件,否则会因为spfile正在时候⽤⽽报错。

Oracle综合测试二(含答案)

Oracle综合测试二(含答案)

综合测试二一、基础设置1.1 创建新用户test1密码test11.2 赋予test1管理员权限1.3 给予用户创建会话的权限1.4 给予用户创建表的权限1.5 修改当前会话的时间显示为以下格式“yyyy-mm-dd hh:mm:ss”二、数据管理操作某个学生运动会比赛信息的数据库,保存了如下的表:表1:运动会信息表gameinfo表2:运动员sporter成绩grade请用SQL语句完成如下功能:1. 在test1用户下建表,注意满足如下要求:a) 定义各个表的主码外码约束b) 运动员的姓名和所属系别不能为空值。

c) 积分要么为空值,要么为6,4,2,0, 分别代表第一,二,三名和其他名次的积分。

2. 往表中插入数据:运动会表(101,秋季运动会,工业大学,2008-8-8,1000,12300.50)运动员(1001, 李明,男,计算机系1002,张三,男,数学系1003, 李四,男,计算机系1004, 王二,男,物理系1005, 李娜,女,心理系1006, 孙丽,女,数学系)项目(x001, 男子五千米,一操场x002,男子标枪,一操场x003, 男子跳远,二操场x004, 女子跳高,二操场x005, 女子三千米,三操场)使用批量操作插入此表数据积分(1001, x001, 61002, x001, 41003, x001, 21004, x001, 01001, x003, 41002, x003, 61004, x003, 21005, x004, 61006, x004, 4)3. 完成如下操作1)查询运动会信息表以文字形式显示运动会的信息。

例如:工业大学秋季运动会在2008年8月8日举行,参加人数1000人,赛会预计费用12,300.50元。

2)由于客观原因,参赛人数减少20%,费用缩减为原来的90%,请更改运动会信息表。

3)1006号运动员的信息更改为孙梦,外语系。

4)计算参加运动会的男女运动员共多少人。

数据库实验报告实验二参考答案[最终版]

数据库实验报告实验二参考答案[最终版]

数据库实验报告实验二参考答案[最终版]第一篇:数据库实验报告实验二参考答案[最终版]1.你的老板要求你创建一个数据量为20G的数据库,但是你现在的硬盘上没有一个这么大空闲容量的分区,只有3个空闲容量为8G的分区,请问,你该如何完成这个任务?答:为该数据库创建3个数据文件,每个数据文件只需保存小于8G的数据,将这3个数据文件分别存储在不同的硬盘分区即可。

注:数据库中的数据都保存在该数据库的若干数据文件中,而非日志文件!2.你想创建一个初始大小为2MB的数据库,但是你却发现你创建的数据库的初始大小是5MB,而且不能小于这个值,请问是什么原因?答:系统数据库中的model数据库为用户创建数据库提供模板,也就是说,在创建数据库时,数据库引擎首先通过复制 Model 数据库中的内容来创建数据库的第一部分,然后再用空页填充新数据库的剩余部分。

因此,用户创建的数据库的初始大小不能小于model数据库的大小。

该问题的原因在于model数据库数据文件的初始大小被设定为5MB。

/***************************SQL语言部分*****************************/ /*创建数据库student*/create database studenton(name=student_data,filename='C:DATAstudent_data.mdf', size=3,maxsize=unlimited,filegrowth=1)log on(name=student_log,filename='C:DATAstudent_log.ldf',size =1,maxsize=20,filegrowth=10%)/*修改数据库student--添加数据文件*/alter database student add filegroup studata /*先增加一个文件组studata*/ goalter database studentadd file(Name=student_data1,filename='D:DATAstudent_data1.nd f',Size=50,Maxsize=500,Filegrowth=30%)to filegroup studata /*删除数据库student */ drop database student第二篇:SQL数据库实验报告实验二实验2SQL Server数据库的管理1.实验目的(1)了解SQL Server 数据库的逻辑结构和物理结构的特点。

oracle教程(第二版)》部分习题参考答案

oracle教程(第二版)》部分习题参考答案

文字性习题答案参见相应章节内容第1章习题1D A C C第2章习题1执行edit命令打开文本编辑器;使用column命令设置列显示宽度习题2CONN scott/tiger@orclSELECT * FROM tab; --本题严谨一些的答案是查询ALL_OBJECTS视图,带条件查询习题3@d:\init_data\init_data.sql习题4SET PAGESIZE 24SET LINESIZE 100COLUMN sal FORMA T $99,990.00第3章习题1D B习题2CONN stu01/stu01pwd@orclCOLUMN USERNAME FORMA T A10SELECT username,granted_role FROM user_role_privs;习题5CREA TE SESSION 系统权限习题11CONN scott/tiger@orclCOLUMN GRANTEE FORMA T A10SELECT grantee,table_name,grantor,privilege,grantableFROM user_tab_privs_made;习题12CONN system/systempwd@orclCOLUMN GRANTEE FORMA T A22SELECT grantee,privilege,admin_option FROM dba_sys_privsORDER BY grantee,privilege;SELECT grantee,granted_role FROM dba_role_privs;使用REVOKE命令回收不必要的系统权限和角色。

\第4章习题8CONN /@cemerp AS SYSDBAALTER USER scott QUOTA 10M ON USERS;习题9CONN system/systempwd@orclCREA TE TABLESPACE data_ts1DA TAFILE '%ORACLE_BASE%\oradata\orcl\data_ts1.dbf' SIZE 10000M REUSE; CREA TE TEMPORARY TABLESPACE temp_ts1TEMPFILE '%ORACLE_BASE%\oradata\orcl\temp_ts1.dbf' SIZE 200M REUSE; CREA TE USER surtec IDENTIFIED BY surtecpwdDEFAULT TABLESPACE data_ts1 TEMPORARY TABLESPACE temp_ts1; GRANT CREA TE SESSION TO surtec;GRANT RESOURCE TO surtec;CONN surtec/surtecpwd@orcl--创建该用户的表emp……--授权给SIBGRANT SELECT ON emp TO sib;GRANT UPDA TE(flag) ON endowment_insurance TO sib;习题10CONN system/systempwd@orclCREA TE USER test01 IDENTIFIED BY test1234;GRANT CREA TE SESSION TO test01;GRANT CREA TE TABLESPACE TO test01;CONN test01/test1234@orclCREA TE TABLESPACE test_tsDA TAFILE '%ORACLE_BASE%\oradata\orcl\test_ts.dbf' SIZE 100KAUTOEXTEND ON NEXT 50K MAXSIZE 5M UNIFORM SIZE 50K;ALTER TABLESPACE test_tsADD DA TAFILE '%ORACLE_BASE%\oradata\orcl\test_ts2.dbf' SIZE 10M; ALTER DA TABASEDA TAFILE '%ORACLE_BASE%\oradata\orcl\test_ts2.dbf' RESIZE 15M ;习题11CONN system/systempwd@orclALTER TABLESPACE pur_tsADD DA TAFILE '%ORACLE_BASE%\oradata\orcl\pur_data.dbf' SIZE 800M; ALTER DA TABASEDA TAFILE '%ORACLE_BASE%\oradata\orcl\pur_data.dbf' RESIZE 2000M ; ALTER DA TABASE DA TAFILE '%ORACLE_BASE%\oradata\orcl\pur_data.dbf' AUTOEXTEND ON NEXT 30M;第5章习题1B A习题8(1)撤销表空间中不允许建立永久方案对象;将方案对象建立在数据表空间即可。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《Oracle数据库技术》
实验指导书2
基本SELECT、WHERE和ORDER BY
子句的使用
实验要求
1)掌握SQL*PLUS的基本使用.
2)掌握SELECT语句的简单用法.
3)掌握WHERE子句的用法。

4)掌握ORDER BY子句的用法。

实验步骤
(1)登录到SQL*Plus,初始用户名:SCOTT,口令为TIGER。

(2)分别显示EMP﹑DEPT﹑SALGRADE表结构,并查看表中的数据.
(3)创建一个查询显示每个雇员的姓名﹑工作﹑受雇日期及雇员编号,并且要将雇员编号作为第一列显示,最后将该SQL语句保存成文件plql.sql,并执行该脚本文件。

(4)将脚本文件plql.sql调取到SQL缓冲区,并将列标题设置为 Emp #,Employee,Job 及Hire Date,将SQL语句保存成文件plq2.sql,最后返回查询结果。

(5)创建一个查询显示工资大于2850美元的姓名及工资。

将该查询保存成脚本文件p2q1.sql,并执行该文件。

(6)修改脚本文件p2q1.sql,显示工资不在1500到2850美元之间的雇员的姓名及工资,并以p2q2.sql文件重新保存该查询。

(7)修改文件p2q2.sql,显示在10和30部门工作并且工资大于1500美元的雇员
的姓名和工资,列标题显示为Employee和MonthlySalary,最后以p2q3.sql重新保存该文件,
返回查询结果。

(8)修改脚本文件p2q3.sql显示奖金比工资多10﹪以上的雇员的姓名﹑工资及奖金。

将该查询保存成p2q4.sql脚本文件,并返回查询结果。

思考练习题
1.下面的SELECT语句能成功执行吗?
SQL>SELECT ename, job, sal Salary
2 FROM emp;
可以执行!
2.下面的语句有三处错误,请纠正它们.
SQL>SELECT empno,ename
2 salary *12 ANNUAL SLARY
3 FROM emp;
3.创建一个查询EMP表中检索出不重复的工作名称
4.创建一个查询显示雇员编号为7566 的雇员的姓名和部门编号。

5.显示受雇时间在’1981-1-20’和’1981-12-1’之间的雇员的姓名、工作、及受雇时间,并以
受雇时间升序排列。

6.显示在10 号和30 号部门工作的雇员的姓名及其部门编号,并以字母顺序排列。

7.显示所有受雇于1982 年的雇员的姓名和受雇日期。

8.显示没有上级管理员的雇员的姓名及其工作。

9.显示能挣得奖金的雇员的姓名、工资、奖金,并以工资和奖金降序排列。

10.显示姓名中第三个字母为A的雇员的姓名。

11.显示姓名中两次出现字母L 并且在30 部门工作或者其管理员编号是7782 的雇员的姓
名。

12.显示工作为clerk 或analyst 并且工资不等于1000、3000、5000 的雇员的姓名、工作
及工资。

相关文档
最新文档