Oracle精选面试题(附答案及分析)
- 格式:doc
- 大小:27.50 KB
- 文档页数:6
需求: 写一个邮件系统, 采用oracle+jsp+servlet来完成.1.创建一个表空间。
2.创建一个用户,将用户赋到表空间上.3.给用户赋权限.4.以新建用户登录,创建一个程序包.5.在表空间上建表,两个表用户表Id intUname varcharUpass varchar邮件表eId intTitle varcharContents varcharUid int 外键附件表Id intFilepath varcharEid int 外键6.作增,删,改,查的操作,全部封装到存储过程中7.写一个java程序来调用.1.解释FUNCTION,PROCEDURE和PACKAGE区别答:function 和procedure是PL/SQL代码的集合,通常为了完成一个任务。
procedure 不需要返回任何值, 而function将返回一个值. 在另一方面,Package是为了完成一个商业功能的一组function和procedure的集合。
2.取某个序列的当前值的PL/SQL语句怎么写?答:SELECT 序列名.CURRVAL FROM DUAL;Create sequence 名字 start with x increment by y maxvalue z nocycle3.说明ORACLE数据库实例与ORACLE用户的关系?答:实例可以包含多个用户,一个用户只能在一个实例下4.创建用户时,需要赋予新用户什么权限才能使它连上数据库?答:grant CONNECT [on 表名] to 用户名5.比较truncate和delete命令?答:两者都可以用来删除表中所有的记录。
区别在于:truncate是DDL(data defining language数据定义语言),它移动HWK,不需要rollback segment(处理事务回滚操作)而Delete是DML(data manufacturing language数据操作语言)操作,需要rollback segment(处理事务回滚操作)且花费较长时间6.给出数据的相关约束类型?答:主键约束,外键约束,非空约束,唯一约束,检查约束。
第1篇1. 请简述Oracle数据库的体系结构,并说明各层的作用。
2. 请解释什么是Oracle实例?实例与数据库之间的关系是什么?3. 请简述Oracle数据库的存储结构,包括数据文件、控制文件、日志文件等。
4. 请说明Oracle数据库的内存结构,包括SGA、PGA等。
5. 请解释Oracle数据库的备份策略,包括全备份、增量备份、差异备份等。
6. 请说明Oracle数据库的恢复策略,包括不完全恢复、完全恢复等。
7. 请解释Oracle数据库的事务管理,包括事务的ACID特性。
8. 请说明Oracle数据库的锁机制,包括共享锁、排他锁等。
9. 请解释Oracle数据库的并发控制,包括多版本并发控制(MVCC)。
10. 请说明Oracle数据库的安全机制,包括角色、权限、用户等。
二、SQL语言1. 请简述SQL语言的组成,包括数据定义语言(DDL)、数据操纵语言(DML)、数据控制语言(DCL)等。
2. 请说明如何创建一个简单的表,包括表结构、字段类型、约束等。
3. 请编写一个查询语句,查询某个表中所有年龄大于30岁的记录。
4. 请编写一个更新语句,将某个表中年龄大于40岁的记录的年龄加1。
5. 请编写一个删除语句,删除某个表中年龄小于20岁的记录。
6. 请编写一个插入语句,插入一条记录到某个表中。
7. 请说明如何使用SQL语句实现分页查询。
8. 请说明如何使用SQL语句实现多表查询。
9. 请说明如何使用SQL语句实现子查询。
10. 请说明如何使用SQL语句实现联合查询。
三、Oracle高级特性1. 请解释什么是视图?如何创建视图?2. 请解释什么是索引?有哪些常见的索引类型?3. 请解释什么是触发器?如何创建触发器?4. 请解释什么是存储过程?如何创建存储过程?5. 请解释什么是函数?如何创建函数?6. 请解释什么是包?如何创建包?7. 请解释什么是序列?如何创建序列?8. 请解释什么是同义词?如何创建同义词?9. 请解释什么是物化视图?如何创建物化视图?10. 请解释什么是分区表?如何创建分区表?四、Oracle性能优化1. 请说明如何查看Oracle数据库的性能统计信息。
数据库oracle面试题及答案数据库Oracle作为一种广泛应用的关系型数据库管理系统,其知识点和面试题目也成为了许多面试者需要关注和准备的重点。
本文将介绍一些常见的Oracle面试题及其答案,希望对广大读者有所帮助。
1. 什么是数据库?简要介绍一下Oracle数据库。
答:数据库是一种结构化数据的集合,用于存储、管理以及访问数据。
Oracle数据库是由Oracle公司开发的一款重要的关系型数据库管理系统,它支持跨平台运行,并且被广泛应用于企业级应用系统中。
2. 请解释什么是数据库事务,以及Oracle中的事务管理。
答:数据库事务是指作为一个逻辑工作单元的一系列数据库操作,要么全部成功完成,要么全部失败回滚到事务开始之前的状态。
Oracle中使用回滚段和日志文件,实现事务的原子性、一致性、隔离性和持久性,通过ACID特性来保证事务的可靠性。
3. Oracle中的连接是什么?请解释一下Oracle中连接的类型。
答:连接是指建立应用程序与数据库之间的连接,使得应用程序能够与数据库交互。
Oracle中的连接类型包括物理连接和逻辑连接。
物理连接是指实际的网络连接,它负责传输数据。
逻辑连接是指应用程序与数据库之间的逻辑连接,通过逻辑连接可以对数据库进行访问和操作。
4. 请举例说明Oracle中的DML和DDL操作。
答:DML操作(数据操纵语言)用于对数据库中的数据进行增删改查,比如INSERT、UPDATE和DELETE语句。
例如,可以使用INSERT语句向表中插入新的记录;使用UPDATE语句修改已有记录;使用DELETE语句删除指定的记录。
DDL操作(数据定义语言)用于定义数据库对象,例如创建表、修改表结构等。
例如,可以使用CREATE TABLE语句创建新的表;使用ALTER TABLE语句修改表结构。
5. 请解释Oracle中的索引是什么以及索引的作用。
答:索引是一种数据结构,用于提高数据库查询的效率。
Oracle⾯试题(基础篇)1. Oracle跟SQL Server 2005的区别?宏观上:1). 最⼤的区别在于平台,oracle可以运⾏在不同的平台上,sql server只能运⾏在windows平台上,由于windows平台的稳定性和安全性影响了sql server的稳定性和安全性2). oracle使⽤的脚本语⾔为PL-SQL,⽽sql server使⽤的脚本为T-SQL微观上:从数据类型, 的结构等等回答2. 如何使⽤Oracle的游标?1). oracle中的游标分为显⽰游标和隐式游标2). 显⽰游标是⽤cursor...is命令定义的游标,它可以对查询语句(select)返回的多条记录进⾏处理;隐式游标是在执⾏插⼊ (insert)、删除(delete)、修改(update)和返回单条记录的查询(select)语句时由PL/SQL⾃动定义的。
3). 显式游标的操作:打开游标、操作游标、关闭游标;PL/SQL隐式地打开SQL游标,并在它内部处理SQL语句,然后关闭它3. Oracle中function和procedure的区别?1). 可以理解函数是存储过程的⼀种2). 函数可以没有参数,但是⼀定需要⼀个返回值,存储过程可以没有参数,不需要返回值3). 函数return返回值没有返回参数模式,存储过程通过out参数返回值, 如果需要返回多个参数则建议使⽤存储过程4). 在sql数据操纵语句中只能调⽤函数⽽不能调⽤存储过程4. Oracle的导⼊导出有⼏种⽅式,有何区别?1). 使⽤oracle⼯具 exp/imp2). 使⽤plsql相关⼯具⽅法1. 导⼊/导出的是⼆进制的数据, 2.plsql导⼊/导出的是sql语句的⽂本⽂件5. Oracle中有哪⼏种⽂件?数据⽂件(⼀般后缀为.dbf或者.ora),⽇志⽂件(后缀名.log),控制⽂件(后缀名为.ctl)6. 怎样优化Oracle数据库,有⼏种⽅式?个⼈理解,数据库性能最关键的因素在于IO,因为操作内存是快速的,但是读写磁盘是速度很慢的,优化数据库最关键的问题在于减少磁盘的IO,就个⼈理解应该分为物理的和逻辑的优化,物理的是指oracle产品本⾝的⼀些优化,逻辑优化是指应⽤程序级别的优化物理优化的⼀些原则:1). Oracle的运⾏环境(⽹络,硬件等)2). 使⽤合适的优化器3). 合理配置oracle实例参数4). 建⽴合适的索引(减少IO)5). 将索引数据和表数据分开在不同的表空间上(降低IO冲突)6). 建⽴表分区,将数据分别存储在不同的分区上(以空间换取时间,减少IO)逻辑上优化:1). 可以对表进⾏逻辑分割,如中国移动⽤户表,可以根据⼿机尾数分成10个表,这样对性能会有⼀定的作⽤2). Sql语句使⽤占位符语句,并且开发时候必须按照规定编写sql语句(如全部⼤写,全部⼩写等)oracle解析语句后会放置到共享池中如: select * from Emp where name=? 这个语句只会在共享池中有⼀条,⽽如果是字符串的话,那就根据不同名字存在不同的语句,所以占位符效率较好3). 数据库不仅仅是⼀个存储数据的地⽅,同样是⼀个的地⽅,⼀些耗时的操作,可以通过存储过程等在⽤户较少的情况下执⾏,从⽽错开使⽤的⾼峰时间,提⾼数据库性能4). 尽量不使⽤*号,如select * from Emp,因为要转化为具体的列名是要查数据字典,⽐较耗时5). 选择有效的表名对于多表连接查询,可能oracle的优化器并不会优化到这个程度, oracle 中多表查询是根据FROM字句从右到左的数据进⾏的,那么最好右边的表(也就是基础表)选择数据较少的表,这样排序更快速,如果有link表(多对多中间表),那么将link表放最右边作为基础表,在默认情况下oracle会⾃动优化,但是如果配置了优化器的情况下,可能不会⾃动优化,所以平时最好能按照这个⽅式编写sql6). Where字句规则Oracle 中Where字句时从右往左处理的,表之间的连接写在其他条件之前,能过滤掉⾮常多的数据的条件,放在where的末尾,另外!=符号⽐较的列将不使⽤索引,列经过了计算(如变⼤写等)不会使⽤索引(需要建⽴起函数), is null、is not null等优化器不会使⽤索引7). 使⽤Exits Not Exits 替代 In Not in8). 合理使⽤事务,合理设置事务隔离性数据库的数据操作⽐较消耗数据库资源的,尽量使⽤批量处理,以降低事务操作次数7. Oracle中字符串⽤什么符号链接?Oracle中使⽤ || 这个符号连接字符串如 ‘abc’ || ‘d’8. Oracle分区是怎样优化数据库的?Oracle的分区可以分为:列表分区、范围分区、散列分区、复合分区。
Oracle⾯试题及答案整理1、表:table1(FId,Fclass,Fscore),⽤最⾼效最简单的SQL列出各班成绩最⾼的列表,显⽰班级,成绩两个字段。
select fclass,max(fscore) from table1 group by fclass,fid2、有⼀个表table1有两个字段FID,Fno,字都⾮空,写⼀个SQL语句列出该表中⼀个FID对应多个不同的Fno的纪录。
类如:101a1001101a1001102a1002102a1003103a1004104a1005104a1006105a1007105a1007105a1007结果:102a1002102a1003104a1005104a1006select t2.* from table1 t1, table1 t2 where t1.fid = t2.fid and t1.fno <> t2.fno;3、有员⼯表empinfo(Fempno varchar2(10) not null pk,Fempname varchar2(20) not null,Fage number not null,Fsalary number not null);假如数据量很⼤约1000万条;写⼀个你认为最⾼效的SQL,⽤⼀个SQL计算以下四种⼈:fsalary>9999 and fage > 35fsalary>9999 and fage < 35fsalary <9999 and fage > 35fsalary <9999 and fage < 35每种员⼯的数量;select sum(case when fsalary > 9999 and fage > 35then 1else 0end) as "fsalary>9999_fage>35",sum(case when fsalary > 9999 and fage < 35then 1else 0end) as "fsalary>9999_fage<35",sum(case when fsalary < 9999 and fage > 35then 1else 0end) as "fsalary<9999_fage>35",sum(case when fsalary < 9999 and fage < 35then 1else 0end) as "fsalary<9999_fage<35"from empinfo;4、表A字段如下month person income⽉份⼈员收⼊要求⽤⼀个SQL语句(注意是⼀个)的处所有⼈(不区分⼈员)每个⽉及上⽉和下⽉的总收⼊要求列表输出为⽉份当⽉收⼊上⽉收⼊下⽉收⼊MONTHS PERSON INCOME---------- ---------- ----------200807 mantisXF 5000200806 mantisXF2 3500200806 mantisXF3 3000200805 mantisXF1 2000200805 mantisXF6 2200200804 mantisXF7 1800200803 8mantisXF 4000200802 9mantisXF 4200200802 10mantisXF 3300200801 11mantisXF 4600200809 11mantisXF 680011 rows selectedselect months, max(incomes), max(prev_months), max(next_months)from (select months,incomes,decode(lag(months) over(order by months),to_char(add_months(to_date(months, 'yyyymm'), -1), 'yyyymm'), lag(incomes) over(order by months), 0) as prev_months,decode(lead(months) over(order by months), to_char(add_months(to_date(months, 'yyyymm'), 1), 'yyyymm'), lead(incomes) over(order by months), 0) as next_months from (select months, sum(income) as incomes from a group by months) aa) aaagroup by months;MONTHS MAX(INCOMES) MAX(PREV_MONTHS) MAX(NEXT_MONTHS)---------- ------------ ---------------- ----------------200801 4600 0 7500200802 7500 4600 4000200803 4000 7500 1800200804 1800 4000 4200200805 4200 1800 6500200806 6500 4200 5000200807 5000 6500 0200809 6800 0 05,表BC1 c22005-01-01 12005-01-01 32005-01-02 5要求的处数据2005-01-01 42005-01-02 5合计 9试⽤⼀个Sql语句完成。
oracle 基础面试题目以下是一些Oracle基础面试题目:1. Oracle是什么?请简要描述它的主要特点和功能。
2. 在Oracle数据库中,什么是数据字典?数据字典的作用是什么?3. 请解释Oracle中的表空间。
表空间在数据库中的作用是什么?4. 什么是Oracle的序列?请描述序列的主要用途。
5. 什么是Oracle的索引?请描述索引在数据库中的作用。
6. 请解释Oracle中的视图。
视图在数据库中的作用是什么?7. Oracle中的存储过程和函数有什么区别?请简要描述。
8. 请解释Oracle中的触发器。
触发器在数据库中的作用是什么?9. 如何在Oracle中执行数据备份和恢复操作?10. 请解释Oracle中的分区表。
分区表在数据库中的作用是什么?11. 什么是Oracle的并行处理?请描述并行处理在数据库中的作用。
12. Oracle中如何使用游标来处理查询结果?请简要描述。
13. 如何在Oracle中创建和管理用户账户?14. 请解释Oracle中的锁定机制。
锁定机制在数据库中的作用是什么?15. 什么是Oracle的性能优化?如何进行性能优化?16. 请解释Oracle中的PL/SQL语言。
PL/SQL在数据库中的作用是什么?17. 如何使用Oracle的存储过程和函数来提高应用程序的性能?18. 请解释Oracle中的物化视图。
物化视图在数据库中的作用是什么?19. 如何使用Oracle的包来组织和管理PL/SQL代码?20. 请解释Oracle中的分布式数据库。
分布式数据库在数据库中的作用是什么?以上是一些常见的Oracle基础面试题目,涵盖了Oracle的基本概念、功能、使用和管理等方面的内容。
希望对你有帮助。
1.-- 查找出部门10中的工种与部门30中任何工种都不相同的职工的姓名与工种。
2.select ename,job from emp3.where deptno=10 and job not in (select distinct job from emp where deptno=30)4.--30号部门工种 select distinct job from emp where deptno=305.6.-- 查找出部门20中的工种相同的职工的姓名与工种。
7.select ename,job from emp8.where deptno=20 and job in9.(select job from emp10.where deptno =2011.group by job12.having count(*)>1);13.14.--先查找出,20号部门中,每个工种的人数超过1人的工种15.select job from emp16.where deptno =2017.group by job18.having count(*)>1;19.20.-- 查找出工资在1000到3500元之间的职工所在部门的所有人员的有关信息。
21.select * from emp22.where deptno in (select deptno from emp where sal between 1000 and 3500);23.24.-- 查找出工资高于20号部门任意一个员工工资的信息。
25.select * from emp26.where sal > (select max(sal) from emp where deptno=20)27.28.-- 查找出工种在部门10中没有的其他部门职工的姓名、工种和工资信息。
29.select ename,job,sal from emp30.where job not in (select distinct job from emp where deptno=10) and deptno != 10;31.32.-- 查找出10号部门中与销售部门中任何职工工种相同的职工的信息。
oracle面试必会6题经典
题目
(1)Oracle数据库与应用程序之间的关系是什么?
Oracle数据库与应用程序之间是一种数据访问关系。
数据库可以存
储应用程序需要的数据,而应用程序可以访问数据库进行查询,增加,修改,删除等操作,从而满足不同的数据访问需求。
(2)什么是Oracle数据库?
Oracle数据库是一种关系型数据库管理系统(RDBMS),它通过使用SQL的强大的查询和事务处理功能来存储和管理数据,还可以提供复杂的
安全性,一致性,可靠性和可扩展性特性。
(3)Oracle数据库是如何储存数据的?
Oracle数据库储存数据使用的是数据文件和控制文件。
数据文件保
存着表和索引等具体的业务数据,而控制文件则保存着数据库的架构和物
理信息,比如表的结构,索引的类型等。
(4)什么是 Oracle PL/SQL?
Oracle PL/SQL是Oracle公司开发的一种基于SQL的编程语言,可
以用来编写复杂的存储过程,包括SQL语句,非SQL语句,数据定义语句,数据控制语句,过程语句等。
(5)什么是Oracle索引?
Oracle索引是Oracle系统中用来加快查询效率的一种结构,它可以以高效的方式索引表中的特定列,或者索引一组列,以便在查询数据时可以更快地找到所需的数据。
(6)Oracle的触发器是什么?
Oracle的触发器是一种特殊的存储过。
oracle面试题及答案IntroductionOracle is one of the leading relational database management systems (RDBMS) in the world. If you are preparing for an Oracle interview, it is important to familiarize yourself with common interview questions and be prepared with accurate and concise answers. In this article, we will discuss some frequently asked Oracle interview questions and provide detailed answers to help you succeed in your interview.1. What is Oracle?Oracle is a powerful and highly popular relational database management system developed by Oracle Corporation. It is used to store, organize, and manage large amounts of data efficiently. Oracle utilizes SQL (Structured Query Language) for querying and manipulating data, providing a comprehensive platform for data management in organizations.2. What are the different components of Oracle architecture?The Oracle architecture consists of several key components, including:a. Oracle Database: The central component that stores data and manages its access.b. Instance: The combination of memory structures and background processes that manage the database.c. Memory Structures: These include the System Global Area (SGA) and the Program Global Area (PGA), which store data and control information.d. Background Processes: These processes handle tasks such as managing memory, ensuring data integrity, and handling user connections.e. Physical Files: These files store the actual data, control files, redo logs, and archived logs.3. Explain the difference between a database and an instance in Oracle.In Oracle, a database refers to the collection of physical files that store data, control information, and other components. An instance, on the other hand, is the combination of memory structures and background processes that manage the database. In simple terms, a database is the stored data, while an instance is the software that operates on the data.4. What is the purpose of the control file in Oracle?The control file is a crucial component of an Oracle database. It contains metadata about the database, such as the database name, the names and locations of data files and redo logs, and the time of the last backup. The control file is used during database startup to verify the structure of the database and maintain consistency.5. How can you kill an Oracle session?To terminate an Oracle session, you can use the following SQL statement:```sqlALTER SYSTEM KILL SESSION '[sid],[serial#]';```Replace `[sid]` with the session ID and `[serial#]` with the serial number of the session you want to terminate. It is important to exercise caution when terminating sessions to avoid data corruption or loss.6. What are the different types of indexes in Oracle?Oracle supports various types of indexes to enhance query performance. Some commonly used index types include:a. B-Tree Index: The most common index type in Oracle, used for equality and range searches.b. Bitmap Index: Efficient for columns with a small number of distinct values.c. Function-Based Index: Created on an expression or function of one or more columns.d. Partitioned Index: Divides the index into smaller, more manageable pieces.e. Cluster Index: Organizes table rows that share common values in one or more columns.7. Explain the difference between COMMIT and ROLLBACK statements.In Oracle, the COMMIT statement is used to permanently save changes made within a transaction. It terminates the current transaction and makes all changes made up to that point visible to other users. On the other hand, the ROLLBACK statement is used to undo changes made within a transaction,reverting the database to its state before the transaction began. ROLLBACK can be issued either voluntarily or in response to an error or exception.8. How does Oracle handle concurrent access to the database?Oracle employs a mechanism called Multi-Version Concurrency Control (MVCC) to handle concurrent access to the database. MVCC allows multiple users to access and modify data simultaneously by providing each user with a snapshot of the data as it existed at the start of their transaction. This ensures data integrity and consistency while avoiding conflicts among concurrent transactions.ConclusionPreparing for an Oracle interview requires a solid understanding of the fundamental concepts and features of Oracle database management. By familiarizing yourself with common interview questions and practicing your answers, you can confidently demonstrate your knowledge and increase your chances of success. Remember to stay calm, organized, and concise in your responses, highlighting your expertise in Oracle and your ability to tackle various challenges in the database management field. Good luck!。
一套Oracle面试题笔试题及参考答案创建表空间neuspace,数据文件命名为neudata.dbf,存放在d:\data目录下,文件大小为200MB,设为自动增长,增量5MB,文件最大为500MB。
(8 分)答:create tablespace neuspace datafile ‘ d:\data\neudata.dbf ' size 200m auto extend on next 5m maxsize 500m;2.假设表空间neuspace 已用尽500MB 空间,现要求增加一个数据文件,存放在e:\appdata目录下,文件名为appneudata,大小为500MB,不自动增长。
(5分)答:alter tablespacen euspace add datafile ‘ e:\appdata\appneudata.dbf ' size 500m;3.以系统管理员身份登录,创建账号tom,设置tom的默认表空间为neuspace。
为tom 分配connect和resource系统角色,获取基本的系统权限。
然后为tom 分配对用户scott的表emp的select权限和对SALARY, MGR 属性的update 权限。
(8 分)答:create user tom identified by jack default tablespace n euspace;Gra nt conn ect, resource totom;Gra nt select, update(salary, mgr) on scott.emp to tom;4.按如下要求创建表class和student。
(15分)属性类型(长度)默认值约束含义CLASSNO 数值(2)无主键班级编号CNAME 变长字符(10)无非空班级名称属性类型(长度)默认值约束含义STUNO 数值(8)无主键学号SNAME变长字符(12)无非空姓名SEX字符(2)男无性别BIRTHDAY日期无无生日EMAIL变长字符(20)无唯一电子邮件SCORE数值(5, 2)无检查成绩CLASSNO 数值(2)无外键,关联到表CLASS的CLASSNO 主键班级编号答:create table class(classno number(2) con stra int class_class no_pk primary key,c name varchar2(10)not nu ll);create table stude nt(stu no nu mber(8) con stra int stude nt_stuno_pk primary key,s name varchar2(12) not n ull,sex char(2) default ‘ 男',birthday date,email varchar2(20) con stra int student_email_uk uniq ue,score nu mber(5,2)con stra int stude nt_score_ck check(score>=0 and score ' 12-5 月-81 ' ;10.完成以下SQL语句。
Oracle精选面试题1.显示10 号部门的所有经理('MANAGER')和20 号部门的所有职员('CLERK')的详细信息答案:Select * from emp where deptno=10 and job=’MANAGER’ or deptno=20 and job=’clerk’;select * from emp where deptno = 10 and job = 'MANAGER' or deptno = 20 and job ='CLERK';2.显示姓名中没有'L'字的员工的详细信息或含有'SM'字的员工信息答案:Select * from emp where ename note like ‘%L%’ or ename like ‘%SM%’;select * from emp where ename not like '%L%' or ename like '%SM%';3.显示各个部门经理('MANAGER')的工资答案:select deptno,emname, salary from emp_wqq where job='MANAGER';4.显示佣金(COMM)收入比工资(SAL)高的员工的详细信息答案:select * from emp where comm > sal;5.把hiredate 列看做是员工的生日,求本月过生日的员工答案:select * from emp where to_char(hiredate, 'mm') = to_char(sysdate , 'mm');6.把hiredate 列看做是员工的生日,求下月过生日的员工答案:select * from emp where to_char(hiredate, 'mm') = to_char(add_months(sysdate,1) , 'mm');7.求1982 年入职的员工答案:select * from emp where to_char(hiredate,'yyyy') = '1982';8.求1981 年下半年入职的员工答案:select * from emp where hiredatebetween to_date('1981-7-1','yyyy-mm-dd') and to_date('1982-1-1','yyyy-mm-dd') - 1;9.求1981 年各个月入职的的员工个数答案:select count(*), to_char(trunc(hiredate,'month'),'yyyy-mm')from emp where to_char(hiredate,'yyyy')='1981'group by trunc(hiredate,'month')order by trunc(hiredate,'month');10.查询各个部门的平均工资答案:select deptno,avg(sal) from emp group by deptno;11.显示各种职位的最低工资答案:select job,min(sal) from emp group by job;12.按照入职日期由新到旧排列员工信息答案:select * from emp order by hiredate desc;13.查询员工的基本信息,附加其上级的姓名答案:select e.*, from emp e, emp e2 where = ;14.显示工资比'ALLEN'高的所有员工的姓名和工资答案:select * from emp where sal > (select sal from emp where ename='ALLEN'); 15.显示与'SCOTT'从事相同工作的员工的详细信息答案:select * from emp where job = (select * from emp where ename='SCOTT');16.显示销售部('SALES')员工的姓名答案:select ename from emp e, dept d where = and ='SALES';17.显示与30 号部门'MARTIN'员工工资相同的员工的姓名和工资答案:select ename, sal from empwhere sal = (select sal from emp where deptno=30 and ename='MARTIN');18.查询所有工资高于平均工资(平均工资包括所有员工)的销售人员('SALESMAN')答案:select * from emp where job='SALESMAN' and sal > (select avg(sal) from emp); 19.显示所有职员的姓名及其所在部门的名称和工资select ename, job, dname from emp e, dept d where = ;20.查询在研发部('RESEARCH')工作员工的编号,姓名,工作部门,工作所在地答案:select empno,ename,dname,loc from emp e, dept dwhere = and danme='RESEARCH';21.查询各个部门的名称和员工人数答案:select * from (select count(*) c, deptno from emp group by deptno) einner join dept d on = ;22.查询各个职位员工工资大于平均工资(平均工资包括所有员工)的人数和员工职位答案:select job, count(*) from emp where sal > (select avg(sal) from emp) group by job;23.查询工资相同的员工的工资和姓名答案:select * from emp e where (select count(*) from emp where sal = group by sal) > 1;24.查询工资最高的3 名员工信息答案:select * from (select * from emp order by sal desc) where rownum <= 3;25.按工资进行排名,排名从1 开始,工资相同排名相同(如果两人并列第1 则没有第2 名,从第三名继续排)答案:select e.*, (select count(*) from emp where sal > +1 rank from emp e order by rank;26.求入职日期相同的(年月日相同)的员工答案:select * from emp e where (select count(*) from emp where =hiredate)>1;27.查询每个部门的最高工资答案:select deptno, max(sal) maxsal from emp group by deptno order by deptno;28.查询每个部门,每种职位的最高工资答案:select deptno, job, max(sal) from emp group by deptno, job order by deptno, job;29.查询每个员工的信息及工资级别select e.*, from emp e, salgrade sg where sal between losal and hisal;30.查询工资最高的第6-10 名员工答案:select * from (select e.*,rownum rn from(select * from emp order by sal desc) ewhere rownum <=10)where rn > 5;31.查询各部门工资最高的员工信息答案:select * from emp e where = (select max(sal) from emp where (deptno = );32.查询每个部门工资最高的前2 名员工答案:select * from emp e where(select count(*) from emp where sal > and = deptno) < 2order by deptno, sal desc;33.查询出有3 个以上下属的员工信息答案:select * from emp e where(select count(*) from emp where = mgr) > 2;34.查询所有大于本部门平均工资的员工信息答案:select * from emp e where sal >(select avg(sal) from emp where (deptno = )order by deptno;35.查询平均工资最高的部门信息答案:select d.*, avgsal from dept d, (select avg(sal) avgsal, deptno from emp group by deptno) se where avgsal = (select max(avg(sal)) from emp group by deptno) and = ;36.查询大于各部门总工资的平均值的部门信息答案:select d.*,sumsal from dept d, (select sum(sal) sumsal, deptno from emp group by deptno) se37.查询大于各部门总工资的平均值的部门下的员工信息答案:select e.*,sumsal from emp e, (select sum(sal) sumsal, deptno from emp group by deptno) sewhere sumsal >(select avg(sum(sal)) from emp group by deptno) and = ;38.查询没有员工的部门信息答案:select d.* from dept d left join emp e on = where empno is null;39.查询当前月有多少天答案:select trunc(add_months(sysdate,1),'month') - trunc(sysdate,'month') from dual;40.列出最低薪金大于1500的各种工作及此从事此工作的全部雇员人数答案:SELECT job,COUNT(empno)FROM empGROUP BY job HAVING MIN(sal)>1500 ;41.列出薪金高于公司平均薪金的所有员工,所在部门,上级领导,公司的工资等级答案:SELECT ,,,,FROM emp e,dept d,emp m,salgrade sWHERE sal>(SELECT AVG(sal) FROM emp) AND = AND =(+) AND BETWEEN AND ;42.列出薪金高于在部门30工作的所有员工的薪金的员工姓名和薪金、部门名称答案:SELECT ,, FROM emp e,dept dWHERE sal > ALL (SELECT sal FROM emp WHERE deptno=30) AND =;43.列出所有部门的详细信息和部门人数答案:SELECT ,,FROM dept d,(SELECT deptno,COUNT(*) count FROM emp GROUP BY deptno) dtWHERE = ;44.显示非销售人员工作名称以及从事同一工作雇员的月工资的总和,并且要满足从事同一工作的雇员的月工资合计大于$5000,输出结果按月工资的合计升序排列答案:FROM empWHERE job<>'SALESMAN'GROUP BY job HAVING sum>5000ORDER BY sum ;45.客户表a(idnameaddress)登陆流水表b(idtime)购物流水表c(idtimeproductidproductnum)46.1.求每个客户的最新登陆时间time,姓名name,客户id答案:select,,astimefromaleftjoin(selectid,max(time)astimefrombgroupbyid)don=;2.查最新登陆并且已经购买商品的客户id,name,登陆的时间time(一条sql语句)答案:select,,astimefroma,(selectid,max(time)astimefrombgroupbyid)dwhere=andexists(select*fromcwhereid=;。