Home Database Mysql Tutorial Oracle查询语句面试题

Oracle查询语句面试题

Jun 07, 2016 pm 05:12 PM
oracle interview questions

Oracle查询语句面试题

01. 查询员工表所有数据,并说明使用*的缺点 select * from emp; 01.查询职(job)为

 查询员工表所有数据,并说明使用*的缺点

select * from emp;
Copy after login

查询职(job)为'PRESIDENT'的员工的工资

select sal from emp where job='PRESIDENT';
Copy after login

【专题推荐】:2020年oracle面试题汇总(最新)

02.查询佣金为0或为null的员工的信息

select * from emp where comm is null or comm=1;
Copy after login

03.查询入职日期在1981-5-1到1981-12-31之间的所有员工的信息

select * from emp where hiredate between to_date(‘1-5月-81’) and to_date(‘31-12月-81’)
Copy after login

04..查询所有名字长度为4的员工的员工的编号,姓名

select empno,ename from emp where length(ename)=4
Copy after login

05.显示10号部门饿所有经理和20号部门的所有员工

select * from emp where job='MANAGER' and deptno=10 or job='CLERK' and deptno=20;
Copy after login

06.显示姓名没有'L'字的员工的详细信息或含有'SM'字的员工信息

select * from emp where ename not like '%L%' or ename like '%SM%';
Copy after login

07.显示各个部门经理的工资

select deptno,sal from emp where job='MANAGER';
Copy after login

08.显示佣金收入比工资高的员工的详细信息

select * from emp where comm>sal;
Copy after login

10.把hiredate列看做是员工的生日,求本月过生日的员工:

SQL> select * from emp
where to_char(hiredate,'mm')=to_char(sysdate,'mm');
Copy after login

11.把hiredate列看做是员工的生日,求下月过生日的员工

SQL> select * from emp
where to_char(hiredate,'mm')=to_char(add_months(sysdate,1),'mm');
Copy after login

12.求1982年入职的员工

SQL> select * from emp where to_char(hiredate,'yyyy')='1982';
Copy after login

hiredate是date类型的,1982是字符串类型的,类型匹配才可以

13.求1981年下半年入职的员工

select * from emp
where hiredate between to_date('1981-7-1','yyyy-mm-dd')
and to_date('1982-1-1','yyyy-mm-dd')-1;
Copy after login

注:to_char()函数和to_date()函数

to_char()函数是把日期的类型转换为指定的格式

to_date()是把字符串转换为日期类型

-1的原因是更精确

14.求1981年各个月入职的员工个数

SQL> select to_char(hiredate,'mm'),count(*) from emp where to_char(hiredate,'yyyy')='1981' group by to_char(hiredate,'mm') order by to_char(hiredate,'mm');
Copy after login

select to_char(hiredate,'mm'),count(*) from emp where to_char(hiredate,'yyyy')='1981' group by to_char(hiredate,'mm') order by to_char(hiredate,'mm');
Copy after login

PartII

01 .查询各个部门的平均工资

SQL> select deptno,avg(nvl(sal,0)) from emp group by deptno;
Copy after login

02.显示各种职位的最低工资

SQL> select job,min(sal) from emp group by job;
Copy after login

03.按照入职日期由新到旧排列员工信息

SQL> select hiredate from emp order by hiredate desc;
Copy after login

04.查询员工的基本信息,附加其上级的姓名(自关联)

SQL> select e.*,e1.ename from emp e,emp e1 where e.mgr=e1.empno;
Copy after login

05.显示工资比’ALLEN’高的所有员工的姓名和工作

SQL> select ename,sal from emp where sal>(select sal from emp where ename='ALLEN');
Copy after login

06.显示与scott从事相同工作的员工的信息(子查询)

SQL> select * from emp where job=(select job from emp where ename='SCOTT');
Copy after login

07.显示销售部(‘SALES’)员工的姓名

SQL> select e.ename from emp e inner join dept d on e.deptno=d.deptno where d.dname='SALES';
Copy after login

08.显示与30号门’MARTIN’员工工资相同的员工的姓名和工资

SQL> select ename,sal from emp where sal=(select sal from emp where deptno=30 and ename='MARTIN');
Copy after login

09.查询所有工资高于平均工资(包括所有员工)的销售人员

SQL> select * from emp where sal>(
select avg(sal) from emp) and job='SALESMAN';
Copy after login

SQL> select * from emp where job='SALESMAN' and sal>(select avg(sal) from emp);
Copy after login

10.显示所有职员的姓名及其所在部门的名称和工资(表连接)

SQL> select e.*,e.sal,d.dname from emp e inner join dept d on e.deptno=d.deptno;
Copy after login

11.查询在研发部(RESEARCH)工作人员的编号,姓名,,工作部门,工作所在地

SQL> select e.empno,e.ename,d.dname,d.loc from emp e inner join dept d on e.deptno=d.deptno where dname='RESEARCH';
Copy after login

12.查询各个部门的名称和员工人数

select e.deptno,d.dname,count(*) from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname
Copy after login

分析:

SQL> select d.dname from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;
DNAME
--------------
ACCOUNTING
RESEARCH
SALES
SQL> select e.deptno,d.dname from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;
DEPTNO DNAME
------ --------------
10 ACCOUNTING
20 RESEARCH
30 SALES
SQL> select e.deptno,d.dname,count(*) from emp e inner join dept d on e.deptno=d.deptno group by e.deptno,d.dname;
DEPTNO DNAME COUNT(*)
------ -------------- ----------
10 ACCOUNTING 3
Copy after login

13.查询各个部门员工工资大于平均工资(平均工资包括所有员工)的人数和员工职位(子查询)

SQL> select count(*),job from emp where sal>(select avg(sal) from emp) group by job;
Copy after login

14.查询工资相同的员工的工资和姓名(子查询)

SQL> select sal,ename from emp e where(select count(*) from emp where sal=e.sal group by sal)>1;
Copy after login

SQL> select e.sal,e.ename from emp e,emp e1 where e.sal=e1.sal and e.ename<>e1.ename;
Copy after login

相关学习推荐:oracle数据库学习教程

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do you alter a table in MySQL using the ALTER TABLE statement? How do you alter a table in MySQL using the ALTER TABLE statement? Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

How do I configure SSL/TLS encryption for MySQL connections? How do I configure SSL/TLS encryption for MySQL connections? Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

How do you drop a table in MySQL using the DROP TABLE statement? How do you drop a table in MySQL using the DROP TABLE statement? Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you create indexes on JSON columns? How do you create indexes on JSON columns? Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

See all articles