Oracle SQL部分练习题
select * from dept where deptno in(select distinct deptno from emp);
select * from dept where deptno in (select deptno from emp group by deptno having count(deptno)>=1);
select * from dept a where exists (select null from emp b where a.deptno=b.deptno);
select ename from emp where sal>(select sal from emp where ename='SMITH');
select e.ename,p.ename from emp e,emp p where p.empno(+)=e.mgr;
select p.ename,e.ename from emp p left join emp e on e.empno=p.mgr;
Execution Plan
----------------------------------------------------------
Plan hash value: 2341341676 ---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 280 | 7 (15)| 00:00:01 |
|* 1 | HASH JOIN OUTER | | 14 | 280 | 7 (15)| 00:00:01 |
| 2 | TABLE ACCESS FULL| EMP | 14 | 140 | 3 (0)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP | 14 | 140 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("E"."EMPNO"(+)="P"."MGR") Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
15 consistent gets
0 physical reads
0 redo size
823 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
select e.ename,(select ename from emp p where p.empno=e.mgr)as BoosName from emp e;
Execution Plan
----------------------------------------------------------
Plan hash value: 4000517069 --------------------------------------------------------------------------------
------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
| --------------------------------------------------------------------------------
------ | 0 | SELECT STATEMENT | | 14 | 140 | 3 (0)| 00:0
0:01 | | 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 10 | 1 (0)| 00:0
0:01 | |* 2 | INDEX UNIQUE SCAN | PK_EMP | 1 | | 0 (0)| 00:0
0:01 | | 3 | TABLE ACCESS FULL | EMP | 14 | 140 | 3 (0)| 00:0
0:01 | --------------------------------------------------------------------------------
------ Predicate Information (identified by operation id):
--------------------------------------------------- 2 - access("P"."EMPNO"=:B1) Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
17 consistent gets
0 physical reads
0 redo size
849 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
14 rows processed
a.
select p.ename from emp e,emp p where e.empno=p.mgr and p.hiredate<e.hiredate;
select e.ename from emp e where e.hiredate<(select hiredate from emp p where p.empno=e.mgr);
select a.dname,b.ename from dept a,emp b where a.deptno=b.deptno(+);
select a.dname,b.ename from dept a left join emp b on a.deptno=b.deptno
select b.ename,a.dname from dept a,emp b where a.deptno=b.deptno and b.job='CLERK';
select min(sal)as minsal,job from emp group by job having min(sal)>1500;
select ename from emp where deptno=(select deptno from dept where dname='SALES');
select ename from emp where sal>(select avg(sal) from emp);
select ename from emp where job=(select job from emp where ename='SCOTT');
select ename,sal from emp where sal in (select sal from emp where deptno=30);
select ename,sal from emp where sal > (select max(sal) from emp where deptno=30);
select a.deptno,a.dname,a.loc,b.ss from dept a,(select deptno,count(ename) ss from emp group by deptno) b
where a.deptno=b.deptno;
select a.ename,b.dname,a.sal from emp a,dept b where a.deptno=b.deptno(+);
select a.ename,b.ename,a.job,b.job,a.deptno,b.deptno from emp a,emp b
where a.job=b.job and a.deptno<>b.deptno;
select a.deptno,a.dname,a.loc,nvl(b.ss,0) from dept a,
(select deptno,count(ename) ss from emp group by deptno) b where a.deptno=b.deptno(+);
select a.deptno,dname,loc,count(empno) ss from dept a,emp b where a.deptno=b.deptno(+)
group by a.deptno,a.dname,a.loc;
select job,min(sal) as minjobsal from emp group by job;
select deptno,min(sal) ss from emp where job='MANAGER' group by deptno;
select ename,(sal*12+nvl(comm,0)) as nianxin from emp order by nianxin;
select ename,a.tt from (select rownum tt,ename,(sal*12+nvl(comm,0)) as nianxin from emp)a where a.tt=4;
select * from (select ename,sal,rank()over(order by sal desc)as nn from emp) where nn=4;
Oracle SQL部分练习题的更多相关文章
- ORACLE SQL语句练习题
--1:选择部门30中的所有员工select * from emp where deptno=30--2:列出所有办事员(clerk) 的姓名.编号和部门编号select empno,ename,de ...
- Oracle SQL Developer 连接 MySQL
1. 在ORACLE官网下载Oracle SQL Developer第三方数据库驱动 下载页面:http://www.oracle.com/technetwork/developer-tools/sq ...
- Oracle sql连接
inner-join left-outer-join right-outer-join full- ...
- 解决Oracle SQL Developer无法连接远程服务器的问题
在使用Oracle SQL Developer连接远程服务器的时候,出现如下的错误 在服务器本地是可以正常连接的.这个让人想起来,跟SQL Server的一些设计有些类似,服务器估计默认只在本地监听, ...
- Oracle sql语句执行顺序
sql语法的分析是从右到左 一.sql语句的执行步骤: 1)词法分析,词法分析阶段是编译过程的第一个阶段.这个阶段的任务是从左到右一个字符一个字符地读入源程序,即对构成源程序的字符流进行扫描然后根据构 ...
- Oracle SQL explain/execution Plan
From http://blog.csdn.net/wujiandao/article/details/6621073 1. Four ways to get execution plan(anyti ...
- 处理 Oracle SQL in 超过1000 的解决方案
处理oracle sql 语句in子句中(where id in (1, 2, ..., 1000, 1001)),如果子句中超过1000项就会报错.这主要是oracle考虑性能问题做的限制.如果要解 ...
- Oracle sql develpoer
Oracle SQL Developer是针对Oracle数据库的交互式开发环境(IDE) Oracle SQL Developer简化了Oracle数据库的开发和管理. SQL Develo ...
- Oracle SQL Developer 添加SQLServer 和Sybase 连接
来源于: http://blog.csdn.net/kk185800961/article/details/8602306 1. 开始只有Oracle 和access 连接 2. 打开Oracle S ...
随机推荐
- image 样式设置
.image-fluid:响应式大小 .image-thumbnails:照片四周会出现一个1px宽的边框 .figure:用于<figure>标签,用来标记一个图像 .figure-ca ...
- c++中冒号(:)和双冒号(::)的用法
1.冒号(:)的用法 (1)表示机构内位域的定义(即该变量占几个bit空间) typedef struct _XXX{ unsigned char a:4; unsigned char c; } ; ...
- 为elasticSearch开发c++接口
一. ElasticSearch是什么 ElasticSearch是目前开源全文搜索引擎的首选,可以快速存储,搜索和分析海量数据.Stack Overflow,Github等都在使用. Elas ...
- 【转】fiddler抓包时出现了tunnel to ......443 解密HTTPS数据
转: 1.在抓取https的数据包时,fiddler会话栏目会显示“Tunnel to….443”的信息,这个是什么原因呢? connect表示https的握手(也就是认证信息,只要是https就要进 ...
- Oracle中对number类型数据to_char()出现各位少0,或者值为###的处理
问题描述: 在Oracle中使用to_char()函数时当number值为小数时,常常个位0不显示 比如:select to_char(0.02) from dual,结果为.02 改进为 selec ...
- 【转】linux下各文件夹的结构说明及用途介绍
linux下各文件夹的结构说明及用途介绍: /bin:二进制可执行命令. /dev:设备特殊文件. /etc:系统管理和配置文件. /etc/rc.d:启动的配 置文件和脚本. /home:用户主目录 ...
- 【bzoj4516】 Sdoi2016—生成魔咒
http://www.lydsy.com/JudgeOnline/problem.php?id=4516 (题目链接) 题意 依次向字符串末尾加上一个字符,每次求不同子串个数. Solution 如果 ...
- GDKOI2018发烧记
偏远小渔村NOIP螺旋升天选手又一次来到了广州参加GDKOI...金实的初三爷们也来啦?要被碾啦T T Day 0 跟HR Lao爷拼(biao)车到了高铁站,上了高铁居然没有颓颓颓吃吃吃(雾),安心 ...
- C#代码连接Oracle数据库一段时间以后[connection lost contact]的问题
最近在使用C#代码连接Oracle数据库,分为两部分,WCF的客户端与服务端.程序启动与运行都没有问题,部署到服务器上后,运行也没有问题.但是第二天再访问的时候,就会抛出下边所示的异常.这是怎么回事? ...
- nginx代理服务器3--高可用(keepalived)
keepalived即健康检查,不停的发送心跳包检查nginx是否活着.Nginx至少两台,一主一备.