oracle实验内容2(共40题)
Oracle答案
Oracle实验一上机作业1.对基本表EMP和DEPT操作:1)列出工资在1000到2000之间的所有员工的ENAME,DID,SALARY。
Select ename,deptno,sal from emp where sal between 1000 and 2000;2)显示DEPT表中的部门号和部门名称,并按部门名称排序。
select deptno,dname from dept order by dname;3)列出部门号在10到20之间的所有员工,并按名字的字母排序。
select * from emp where deptno between 10 and 20 order by ename;4)显示名字中包含TH和LL的员工名字。
select * from emp where ename like *%TH%*or ename like *%LL%*;5)显示在1983年中雇佣的员工。
select ename,hiredate from emp where to_char(hiredate,*YYYY*)=*1983*6)查询每个部门的平均工资。
Select deptno ,avg(sal) from emp group by deptno;7)查询出每个部门中工资最高的职工。
select * from emp where sal in (select max(sal) from emp group by deptno);8)查询出每个部门比平均工资高的职工人数。
select a.deptno,count(*) from emp a,(select deptno,avg(sal) avgsal from emp group by deptno) b where a.deptno=b.deptno and a.sal>b.avgsal group by a.deptno;2.生成一个数据表PROJECTS,其字段定义如下,其中PROJID是主键并且要求P_END_DATE不能比P_START_DATE早。
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数据库管理与工具使用班级:座号:姓名:时间:一、【实验目的】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测试题+答案
Oracle测试题+答案1) PL/SQL块中可以使用下列()命令。
(选择两项)a) TRUNCATEb) DELETEc) SA VEPOINTd) ALTER TABLE2) 授予sa用户在SCOTT.EMP表中SAL列的更新权限的语句是(B)〔选择一项〕a) GRANT CHANGE ON SCOTT.EMP TO SAb) GRANT UPDA TE ON SCOTT.EMP(SAL) TO SAc) GRANT UPDA TE (SAL) ON SCOTT.EMP TO SAd) GRANT MODIFY ON SCOTT.EMP(SAL) TO SA3) EMP表有14条记录,则语句SELECT ‘Aptech’FROM EMP 的执行结果是(C)〔选择一项〕a) Aptechb) 无输出c) 14行Aptechd) 编译出错4) PL/SQL块中哪几部分是可选的()〔选择二项〕a) Declareb) Beginc) Exceptiond) Constant5) 在创建序列的过程中,下列()选项指定序列在达到最大值或最小值后,将继续从头开始生成值。
(选择一项)a) Cycleb) Nocyclec) Cached) Nocache6) 同义词有以下()用途。
(选择三项)a) 简化SQL 语句b) 隐藏对象的名称和所有者c) 提供对对象的公共访问d) 显示对象的名称和所有者7) Oracle中用来释放锁的语句有()〔选择二项〕a) commitb) Drop lockc) rollbackd) unlock8) 关于类型定义Number(9,2)说法正确的有()〔选择一项〕a) 整数部分9位,小数部分2位,共11位b) 整数部分7位,小数部分2位,共9位c) 整数部分6位,小数点一位,小数部分2位,共9位d) 以上说法均不正确9) 下列哪种Lob类型用来存储数据库以外的操作系统文件()〔选择一项〕a) CLOBb) BLOBc) CFILEd) BFILE10) Oracle中的三种系统文件分别是()〔选择三项〕a) 数据文件b) 归档文件c) 日志文件d) 控制文件11) 下列哪项不是Oracle中常用的分区方法?()〔选择一项〕a) 范围分区b) 散列分区c) 列表分区d) 条件分区12) 查看Test中名称为P1的分区中的记录的查询语句为()〔选择一项〕a) Select * from Test Where PartitionName=’p1’b) Select * from Test(p1)c) Select * from Test Partition(p1);d) 以上均正确13) 创建序列时,若未指定Cycle选项,则当当前值大于MaxValue时将()〔选择一项〕a) 从MinValue重新开始循环b) 重复使用MaxValue 值c) 执行出错d) 使用随机值14) 下列哪项是创建索引组织表所必需的()〔选一项〕a) Primary Keyb) Order Byc) Group Byd) 以上均不是15) 若表的某字段值存在大量的重复,则基于该字段适合创建哪种索引?()〔选一项〕a) 标准索引b) 唯一索引c) 位图索引d) 分区索引16) 在PL/SQL块中定义一个名为PI值为3.14的Real型常量的语法是()〔选一项〕a) A.Pi Const Real=3.14;b) B.Pi Real Const =3.14;c) C.Constant Pi Real:=3.14d) D.Pi Constant Real:=3.1417) 22.当Select语句没有返回行时,将引发下列哪个异常?()[选择一项]a) A.No_rows_foundb) B.No_data_foundc) C.No_Data_rows_foundd) D.Invalid_Number18) Oracle中提供的两种游标是()〔选择二项〕a) A.隐式游标b) B.静态游标c) C.REF游标d) D.显式游标19) 若Emp表中有14条记录,则用户执行了以下操作,结果是:()〔选择一项〕Cursor mycur is Select * From emp;。
oracle测试试题及答案
【例1】创建一个名为IT_EMPLOYEES的表,它由编号EMPLOYEE_ID、名FIRST_NAME、姓LAST_NAME、邮箱EMAIL、电话号码PHONE_NUMBER、部门编号JOB_ID、薪资SALARY和部门经理编号MANAGER_ID八个属性组成。
create table IT_EMPLOYEES(EMPLOYEE_ID NUMBER(6) not null unique,FIRST_NAME VARCHAR2(20),LAST_NAME VARCHAR2(25) not null,EMAIL VARCHAR2(25),PHONE_NUMBER VARCHAR(20),JOB_ID VARCHAR2(10),SALARY NUMBER(8,2),MANAGER_ID NUMBER(6));【例2】建立程序员的视图PROG_EMPLOYEES(JOB_ID=’IT_PROG’),其中隐含了视图的列名.create view prog_employeesasselect employee_id,first_name,last_name,email,phone_number,salary,manager_id from it_employeeswhere job_id = 'IT_PROG';【例3】执行下面的CREATE INDEX语句,创建索引:CREATE INDEX IT_LASTNAME ON IT_EMPLOYEES(LAST_NAME);【例4】将前文创建的视图PROG_EMPLOYEES删除.DROP VIEW PROG_EMPLOYEES;【例5】向IT_EMPLOYEES表中增加“雇员生日”列,其数据类型为日期型:ALTER TABLE IT_EMPLOYEES ADD BIRTHDATE DATE;【例6】将IT_EMPLOYEES表的MANAGER_ID字段改为8位:ALTER TABLE IT_EMPLOYEES MODIFY MANAGER_ID NUMBER(8);【例7】删除IT_EMPLOYEES表EMPLOYEE_ID字段的UNIQUE约束:ALTER TABLE IT_EMPLOYEES DROP UNIQUE(EMPLOYEE_ID);【例8】创建表COUNTRIES时的列顺序为:COUNTRY_ID、COUNTRY_NAME、REGION_ID。
Oracle练习题习题答案张表题
Oracle练习题+习题答案(张表+题)create table student( sno varchar2(10) primary key,sname varchar2(20),sage number(2),ssex varchar2(5));create table teacher(tno varchar2(10) primary key,tname varchar2(20));create table course(cno varchar2(10),cname varchar2(20),tno varchar2(20),constraint pk_course primary key (cno,tno));create table sc(sno varchar2(10),cno varchar2(10),score number(4,2),constraint pk_sc primary key (sno,cno));/*******初始化学生表的数据******/insert into student values ('s001','张三',23,'男');insert into student values ('s002','李四',23,'男'); create table student(insert into student values ('s003','吴鹏',25,'男'); sno varchar2(10) primary key,insert into student values ('s004','琴沁',20,'女'); sname varchar2(20),insert into student values ('s005','王丽',20,'女'); sage number(2),insert into student values ('s006','李波',21,'男'); ssex varchar2(5)insert into student values ('s007','刘玉',21,'男'); );insert into student values ('s008','萧蓉',21,'女');insert into student values ('s009','陈萧晓',23,'女');insert into student values ('s010','陈美',22,'女');commit;/******************初始化教师表***********************/ insert into teacher values ('t001', '刘阳');create table teacher(insert into teacher values ('t002', '谌燕');tno varchar2(10) primary key,insert into teacher values ('t003', '胡明星');tname varchar2(20)commit; );/***************初始化课程表****************************/ insert into course values ('c001','J2SE','t002');insert into course values ('c002','Java Web','t002');insert into course values ('c003','SSH','t001'); create table course(insert into course values ('c004','Oracle','t001'); cnovarchar2(10),insert into course values ('c005','SQL SERVER 2005','t003'); cname varchar2(20),insert into course values ('c006','C#','t003'); tno varchar2(20),insert into course values ('c007','JavaScript','t002');constraint pk_course primary key (cno,tno)insert into course values ('c008','DIV+CSS','t001'); );insert into course values ('c009','PHP','t003');insert into course values ('c010','EJB3.0','t002');commit;/***************初始化成绩表***********************/insert into sc values ('s001','c001',78.9);insert into sc values ('s002','c001',80.9);create table sc(insert into sc values ('s003','c001',81.9);sno varchar2(10),insert into sc values ('s004','c001',60.9);cno varchar2(10),insert into sc values ('s001','c002',82.9);score number(4,2),insert into sc values ('s002','c002',72.9);constraint pk_sc primary key (sno,cno)insert into sc values ('s003','c002',81.9); ); insert into sc values ('s001','c003','59'); commit;练习:注意:以下练习中的数据是根据初始化到数据库中的数据来写的SQL 语句,请大家务必注意。
Oracle实验报告2标准答案
(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数据库》实验安排[内容要求]请完成下列上机实验,按附录1要求书写实验报告,记录实验过程和完成命令及结果(运行结果需截图,命令请复制粘贴文本)。
[上交时间]每人递交一份打印并装订好的实验报告,于课程结束时上交,迟交者实验成绩计0分。
实验一安装和使用Oracle数据库【实验目的】1.掌握Oracle软件安装过程,选择安装组件2.掌握建立Oracle数据库,配置网络连接3.掌握Oracle企业管理器的基本操作4.使用SQL*Plus,登录到实例和数据库5.掌握命令方式的关闭和启动实例及数据库【实验内容】1.查看已安装的Oracle组件2.查看服务,记录下和数据库有关的服务名,将他们设为手动方式,启动相关服务。
3.配置监听器,查看是否在服务中有LISTENER,是否能启动4.配置本地net服务,提示:设置正确的服务器地址和端口号。
5.打开SQL*Plus,用SYS和SYSTEM用户名和密码登录。
6.思考题:有几种打开SQL*Plus的方法?分别是什么?两种,7.用命令关闭实例和数据库,记录命令SOL >shutdown normal8.用命令以NOMOUNT的方式启动实例,再加载数据库,打开数据库。
实验二体系结构、存储结构与各类参数【实验目的】1.理解Oracle体系结构2.了解初始化参数文件以及初始化参数的含义3.掌握查看三类数据字典视图和动态性能视图的方法【实验内容】1.如何查看初始化参数?有哪几种方法?1.show parameters 参数名2、select [列名] from 表名2.初始化文件有几种?默认的保存位置在哪里?1、.Spfile 默认位置:$oracle_home\\database\\dbs2.Pfile默认位置:$oracle_home\\admin\\pfile3.在SQL*Plus中查看数据字典和动态性能视图,完成下面题目将命令和结果写入实验报告。
Oracle测试题+答案
1) PL/SQL块中可以使用下列()命令。
(选择两项)a) TRUNCATEb) DELETEc) SA VEPOINTd) ALTER TABLE2) 授予sa用户在SCOTT.EMP表中SAL列的更新权限的语句是(B)〔选择一项〕a) GRANT CHANGE ON SCOTT.EMP TO SAb) GRANT UPDA TE ON SCOTT.EMP(SAL) TO SAc) GRANT UPDA TE (SAL) ON SCOTT.EMP TO SAd) GRANT MODIFY ON SCOTT.EMP(SAL) TO SA3) EMP表有14条记录,则语句SELECT ‘Aptech’FROM EMP 的执行结果是(C)〔选择一项〕a) Aptechb) 无输出c) 14行Aptechd) 编译出错4) PL/SQL块中哪几部分是可选的()〔选择二项〕a) Declareb) Beginc) Exceptiond) Constant5) 在创建序列的过程中,下列()选项指定序列在达到最大值或最小值后,将继续从头开始生成值。
(选择一项)a) Cycleb) Nocyclec) Cached) Nocache6) 同义词有以下()用途。
(选择三项)a) 简化SQL 语句b) 隐藏对象的名称和所有者c) 提供对对象的公共访问d) 显示对象的名称和所有者7) Oracle中用来释放锁的语句有()〔选择二项〕a) commitb) Drop lockc) rollbackd) unlock8) 关于类型定义Number(9,2)说法正确的有()〔选择一项〕a) 整数部分9位,小数部分2位,共11位b) 整数部分7位,小数部分2位,共9位c) 整数部分6位,小数点一位,小数部分2位,共9位d) 以上说法均不正确9) 下列哪种Lob类型用来存储数据库以外的操作系统文件()〔选择一项〕a) CLOBb) BLOBc) CFILEd) BFILE10) Oracle中的三种系统文件分别是()〔选择三项〕a) 数据文件b) 归档文件c) 日志文件d) 控制文件11) 下列哪项不是Oracle中常用的分区方法?()〔选择一项〕a) 范围分区b) 散列分区c) 列表分区d) 条件分区12) 查看Test中名称为P1的分区中的记录的查询语句为()〔选择一项〕a) Select * from Test Where PartitionName=’p1’b) Select * from Test(p1)c) Select * from Test Partition(p1);d) 以上均正确13) 创建序列时,若未指定Cycle选项,则当当前值大于MaxValue时将()〔选择一项〕a) 从MinValue重新开始循环b) 重复使用MaxValue 值c) 执行出错d) 使用随机值14) 下列哪项是创建索引组织表所必需的()〔选一项〕a) Primary Keyb) Order Byc) Group Byd) 以上均不是15) 若表的某字段值存在大量的重复,则基于该字段适合创建哪种索引?()〔选一项〕a) 标准索引b) 唯一索引c) 位图索引d) 分区索引16) 在PL/SQL块中定义一个名为PI值为3.14的Real型常量的语法是()〔选一项〕a) A.Pi Const Real=3.14;b) B.Pi Real Const =3.14;c) C.Constant Pi Real:=3.14d) D.Pi Constant Real:=3.1417) 22.当Select语句没有返回行时,将引发下列哪个异常?()[选择一项]a) A.No_rows_foundb) B.No_data_foundc) C.No_Data_rows_foundd) D.Invalid_Number18) Oracle中提供的两种游标是()〔选择二项〕a) A.隐式游标b) B.静态游标c) C.REF游标d) D.显式游标19) 若Emp表中有14条记录,则用户执行了以下操作,结果是:()〔选择一项〕Cursor mycur is Select * From emp;。
oracle 实验题 管理控制文件附带答案
实验八管理控制文件一目的和要求1 掌握控制文件的作用、内容2 掌握控制文件的多路复用3 熟练掌握控制文件的备份4 熟悉控制文件的创建、删除5 会查看某个数据库服务器使用的控制文件6 会在OEM中查看及管理控制文件二实验内容1控制文件的作用和内容是什么?答:控制文件的作用是:根据参数control_files来定位控制文件,从中获取数据库物理结构信息。
内容是:a)控制文件所属的数据库名称,创建时间等信息,一个控制文件只能属于一个数据库。
(V$database)b)表空间名称。
(v$tablespace)c)相关数据文件(V$datafile)、日志文件组(V$log)、日志文件(V$logfile)的信息。
d)相关数据库是否归档(V$database) 、归档日志的信息。
(V$Archived_log)e)相关数据库的备份信息。
(V$backup)2具体实验:(结果贴图表示)1)查询当前数据库服务器使用的控制文件有哪些?SQL> show parameter control_files;2)实现控制文件多路复用,位置是:‘C:\oracle\product\10.2.0\oradata\orcl\control01.ctl’,‘C:\oracle\product\10.2.0\oradata\orcl\control02.ctl’,‘C:\oracle\product\10.2.0\oradata\orcl\control03.ctl’, ‘D:\control04.ctl’步骤:SQL> conn sys/o123 as sysdba;SQL>alter system set control_files=‘C:\oracle\product\10.2.0\oradata\orcl\control01.ctl’, ‘C:\oracle\product\10.2.0\oradata\orcl\control02.ctl’,‘C:\oracle\product\10.2.0\oradata\orcl\control03.ctl’, ‘D:\control04.ctl’ scope=spfile; SQL>shutdown immediateSQL>host copy C:\oracle\product\10.2.0\oradata\orcl\control01.ctl D:\control04.ctlSQL>startupSQL>show parameter control_files;3)备份控制文件:3.1)备份成为二进制文件:SQL>alter database backup controlfile to ‘d:\control.bkp’;3.2) 将控制文件备份成为文本文件:(即将控制文件翻译成创建它时的脚本,存放为trace文件)SQL>alter database backup controlfile to trace;4)创建控制文件把刚才备份控制文件得到的文本文件找到并打开,复制其中Set #1. NORESETLOGS case 部分的创建控制文件的代码,写在一个sql脚本中,保存成d:\createcontrolfile.sql SQL>startup nomount;SQL>get d:\createcontrolfile.sqlSQL>/执行创建控制文件答:show parameter user_dump_dest;找到其指定的目录;复制代码;在E盘写脚本;5)移除、删除控制文件主要是修改参数control_files的值,后对文件做移动位置或删除处理。
oracle实验
数据库实训考试试题试题:1、写一个pl/sql程序块:直接使用数据类型定义两个变量v_empno 和v_ename,从scott模式下的emp表中检索某个员工的编号empno 和姓名ename,存储到v_empno和v_ename,并输出此员工的编号和姓名。
代码:set serveroutput ondeclarev_empno varchar2(10);v_ename varchar2(20);beginselect empno,ename into v_empno,v_ename from scott.empwhere empno=7902;dbms_output.put_line(v_empno || '和' || v_ename);end;/2、写一个pl/sql程序块:根据scott模式下的emp表中的部门编号deptno字段的值,为姓名为SCOTT的雇员修改工资;若他所在部门号为10,则工资加100;若部门号为20,则工资加300;否则工资加400。
代码:declarev_deptno emp.deptno%type;V_sal emp.sal%type;beginselect deptno,salinto v_deptno ,v_salfrom empwhere ename = 'SCOTT';if v_deptno = 10 thenv_sal:=v_sal + 100;elsif v_deptno = 20 thenv_sal:=v_sal + 300;elsev_sal:=v_sal + 400;end if;update emp set sal=v_sal where ename='SCOTT';end;/3、写一个pl/sql程序块:定义一个游标类型type_cursor,然后使用type_cursor定义变量ref_cur;根据scott模式下的emp表和dept表,使用游标变量ref_cur检索员工姓名和工作信息,并输出员工姓名和工作信息;使用游标变量ref_cur检索部门编号和部门名称信息,并输出部门编号和部门名称信息。
(完整word版)Oracle测试题
ORACLE测试题一、选择题:(本题共20个小题,每小题2分,共40分)1。
下列哪个子句实现对一个结果集进行分组和汇总( D )。
A.HAVINGB.ORDER BY C。
WHERE D.GROUP BY2.在Oracle中创建用户时,若未提及DEFAULT TABLESPACE关键字,则Oracle 就将( C )表空间分配给用户作为默认表空间。
A.HR B.SCOTT C.SYSTEM D.SYS3。
有字符串数据"test”分别存放到char(10)和varchar2(10)类型的字段中,其实际存储长度为( A )A。
10 4 B。
4 4 C。
10 10 D. 4 104.在Oracle中,当控制一个显式游标时,下面哪种命令包含INTO子句()。
A. FETCH B。
CLOSE C。
OPEN D。
CURSOR5. 在Oracle中,有一个教师表teacher的结构如下:ID NUMBER(5),NAME VARCHAR2(25),EMAIL VARCHAR2(50)下面哪个语句显示没有Email地址的教师姓名(C)A.SELECT name FROM teacher WHERE email = NULL;B.SELECT name FROM teacher WHERE email <> NULL;C.SELECT name FROM teacher WHERE email IS NULL;D.SELECT name FROM teacher WHERE email IS NOT NULL;6。
如果a表原本是空表,请问执行下列语句后,以下哪个表述正确(A)insert into a values(1,'abc’,’1’);insert into a values(2,’abc’,’2’);create table b as select * from a;rollback;A.a表b表都没有数据B.a表b表都有两行数C.a表有数据,b表没有数据D.a表没有数据,b表有数据7. 如何删除sales表中产品类型为toys的profits列的列值?BA。
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期末考试试题及答案一、选择题(每题2分,共40分)1. ORACLE数据库系统属于以下哪一种数据库类型?A. 关系型数据库B. 层次型数据库C. 网状型数据库D. 对象-关系型数据库答案:A2. 在ORACLE中,以下哪个命令用来创建一个表?A. CREATE TABLEB. CREATE VIEWC. CREATE INDEXD. CREATE SEQUENCE答案:A3. 数据库的三级模式结构包括以下哪几个层次?A. 外模式、概念模式、内模式B. 概念模式、内模式、物理模式C. 外模式、内模式、物理模式D. 外模式、概念模式、物理模式答案:A4. 在ORACLE中,以下哪个命令用来删除一个表?A. DROP TABLEB. DELETE TABLEC. DROP VIEWD. DELETE VIEW答案:A5. 数据库事务的四个特性包括以下哪些?A. 原子性、一致性、隔离性、持久性B. 原子性、一致性、独立性、持久性C. 原子性、一致性、并发性、持久性D. 原子性、一致性、并发性、独立性答案:A6. 在ORACLE中,以下哪个命令用来修改表的结构?A. ALTER TABLEB. MODIFY TABLEC. UPDATE TABLED. ALTER VIEW答案:A7. 数据库的备份分为以下哪几种类型?A. 冷备份、热备份、逻辑备份B. 冷备份、热备份、物理备份C. 冷备份、热备份、完全备份D. 冷备份、热备份、增量备份答案:D8. 在ORACLE中,以下哪个命令用来创建一个索引?A. CREATE INDEXB. CREATE TABLEC. CREATE VIEWD. CREATE SEQUENCE答案:A9. 数据库的并发控制主要包括以下哪些方法?A. 乐观并发控制、悲观并发控制、时间戳并发控制B. 乐观并发控制、悲观并发控制、锁并发控制C. 乐观并发控制、悲观并发控制、令牌并发控制D. 乐观并发控制、悲观并发控制、版本并发控制答案:B10. 在ORACLE中,以下哪个命令用来创建一个序列?A. CREATE SEQUENCEB. CREATE TABLEC. CREATE VIEWD. CREATE INDEX答案:A二、填空题(每题2分,共20分)1. 在ORACLE中,使用______命令可以创建一个表。
oracle实验以及答案
实验1SQL*Plus的使用和基本SELECT语句实验目的通过该实验使学员掌握简单查询语句的基本使用方法以及别名的指定方法,能够创建和执行SQL脚本。
实验要求(1)掌握SQL*Plus的基本使用(2)掌握SELECT语句的简单用法。
实验步骤(1)登录到SQL*Plus,初始用户名为:SCOTT,口令为TIGER。
答:打开sql plus,输入用户名和密码登陆;也可以从dos窗口输入命令sqlplus Scott/tiger 连接数据库(2)分别显示EMP、DETP、SALGRADE表结构,并察看表中的数据。
答:DESC emp;DESC dept;DESC salgrade;(3)创建一个查询显示每个雇员的姓名、工作、受雇日期及雇员编号,并且要将雇员编号作为第一列显示。
最后将该SQL语句保存成文件p1q1.sql,并执行该脚本文件。
答:SELECT empno,ename,job,hiredate FROM emp;(4)将脚本文件p1q1.sql调取到SQL缓冲区,并将列标题设置为Emp #,Employee,Job及Hire Date,将该SQL语句保存成文件p1q2.sql,最后返回查询结果。
答:SELECT empno "Emp #",ename "Employee",job "Job",hiredate "Hire Date" FROMemp;思考练习题1.SQL*Plus命令是用于访问数据库的吗?答:可以访问数据库。
2.下面的SELECT语句能成功执行吗?SQL>SELECT ename,job,sal Salary2FROM emp;答:可以成功执行。
3.下面的语句有3处错误,请纠正它们。
SQL>SELECT empno,ename2Salary x 12 ANNUAL SALARY3FROM emp;答:A.表中没有Salary项,改为sal;B.ename后缺少逗号。
Oracle数据库试题100题(附答案)
Oracle数据库试题100题(附答案)1.当Oracle服务器启动时,下列哪种文件不是必须的(D)。
A.数据文件B.控制文件C.日志文件D.归档日志文件2.在Oracle中,当用户要执行SELECT语句时,下列哪个进程从磁盘获得用户需要的数据(B)。
A.用户进程B.服务器进程C.日志写入进程(LGWRD.检查点进程(CKPT)3.在Oracle中,一个用户拥有的所有数据库对象统称为(B)。
A.数据库B.模式C.表空间D.实例4.在Oracle中,有一个教师表teacher的结构如下:ID NUMBER(5)NAME V ARCHAR2(25)EMAIL VARCHAR2(50)下面哪个语句显示没有Email地址的教师姓名(C)。
A.SELECT name FROM teacher WHERE email = NULL;B.SELECT name FROM teacher WHERE email <> NULL;C.SELECT name FROM teacher WHERE email IS NULL;D.SELECT name FROM teacher WHERE email IS NOT NULL;5.在Oracle数据库的逻辑结构中有以下组件:A 表空间B 数据块C 区D 段这些组件从大到小依次是(B)。
A.A→B→C→DB.A→D→C→BC.A→C→B→DD.D→A→C→B6.在Windows操作系统中,Oracle的(A)服务监听并接受来自客户端应用程序的连接请求。
A.OracleHOME_NAMETNSListenerB.OracleServiceSIDC.OracleHOME_NAMEAgentD.OracleHOME_NAMEHTTPServer7.在Oracle 中创建用户时,若未提及DEFAULT TABLESPACE 关键字,则Oracle 就将(B)表空间分配给用户作为默认表空间。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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)。