oracle 查询测试样题

1.
select count(*) from employees
where last_name like '_A%';

key:0

2.
select count(*)
from employees
where to_char(hire_date,'YYYY')=1998;

select count(*)
from employees
where hire_date like '%98';

key:23

select to_char(hire_date,'YYYY') from employees;

3.
select job_title, max_salary-min_salary as "SAL_DIEF"
from jobs
order by max_salary-min_salary desc;

select job_title,(max_salary-min_salary) as "SAL_DIEF"
from jobs
order by 2 desc;

19行记录

4.
select count(*)
from employees
where (salary>12000 or salary<1000)
and job_id !='ST_MAN' and job_id!='SH_CLERK' ;

number:6

================
select count(*)
from employees
where salary not between 1000 and 12000
and job_id not in('ST_MAN','SH_CLERK') ;

select salary
from employees
where salary<1000
and salary>12000;
--当它判断1000为假时就不判断后面的大于12000了.

select job_id from employees;

select * from employees
where job_id in('ST_MAN','SH_CLERK');
--工作岗位名称要加单引号

5.
select count(*)
from employees
where to_char(hire_date,'YYYY')=1999
and to_char(hire_date,'mm')=02;

key:3

select count(*)
from employees
where to_char(hire_date,'YYYY-MM')='1999-02';

6.

select last_name,salary,
decode(trunc(salary/1500),0,'A',
		   1,'B',
                   2,'C',
		     'D'
) Grade
from employees
where last_name like'%s';

7.
select d.department_id,d.department_name,l.city
from departments d,locations l
where d.department_id in(10,40,90)
and d.location_id=l.location_id;

8.
select l.city,c.country_name,r.region_name
from locations l,regions r,countries c
where l.location_id=1000
and l.country_id=c.country_id
and c.region_id=r.region_id;

9.
select  m.last_name "MAN_NAME",nvl(e.last_name,'NO EMPLOYEES') "EMP_NAME"
from employees m,employees e
where m.department_id=100
and m.employee_id=e.manager_id(+);

10行记录

select  m.last_name MAN_NAME,nvl(e.last_name,'NO EMPLOYEES') EMP_NAME
from employees m,employees e
where m.department_id=100
and m.employee_id=e.manager_id(+);

10
select department_id,count(*) NUM
from employees
where salary>8000
group by department_id
;
9行记录

11
select department_id,count(*) NUM
from employees
where salary>5000
group by department_id
having count(*)>3;

3行记录

12
select last_name,salary
from employees
where salary>
(select salary from employees where employee_id=110)
and department_id=100;

2行记录

13
select count(*) NUM
from employees
where commission_pct<all
(select distinct commission_pct
from employees
where salary>12000
and commission_pct is not null
);
24行记录
时间: 2024-11-12 00:08:36

oracle 查询测试样题的相关文章

oracle查询转换_inlist转换

oracle的optimizer会对一些sql语句进行查询转换,比如: 合并视图 子查询非嵌套化 inlist转换 下面讲讲遇到的in list转化优化的案例: create table test( col1 varchar2(12) col2 number ext varchar2(4000) ); create index test_ind on test(user_id, col2); create sequence seq_test cache 200; 第一步:准备一些测试数据(10个

oracle查询转换_view merge

oracle对于子查询的支持做的很好,oracle optimizer会对inline view进行query transfomation,即视图合并,不过也经常带来意想不到的问题.下面是一个inline view的merge的例子: 1, 创建临时表 1 create table test1 as select * from dba_objects; 2 create table test2 as select * from dba_objects; 2, 以下查询语句 select * fr

Oracle查询总结

-------------------------------多表查询-------------------------------------- --笛卡尔积查询. select * from emp,dept;--结果为64条,emp表有14条,dept表有4条 --别名查询 --改变查询后的结果显示的列名,在字段后面写要显示的列名(注意一定要用双引号括起来,oracle查询中之后这里用到双引号!) select ename "name" ,loc "地点" f

45个非常有用的 Oracle 查询语句小结

 这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收藏吧. 原文地址:http://www.jbxue.com/db/19890.html 日期/时间 相关查询 1.获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 "SYSDATE"来指定查询的日期. 复制代码代码如下: SELECT TRUNC

Oracle查询被锁的表及进程的方法

Oracle查询可以有多种方法,下面为您介绍的是如何Oracle查询被锁的表及Oracle查询连接的进程的方法,希望对您能够有所帮助. 一.查看被锁的表 select p.spid,a.serial#, c.object_name,b.session_id,b.oracle_username,b.os_user_name from v$process p,v$session a, v$locked_object b,all_objects c where p.addr=a.paddr and a

45 个非常有用的 Oracle 查询语句

这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收藏吧! 日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 "SYSDATE"来指定查询的日期. ? 1 2 SELECT TRUNC (SYSDATE, 'MONTH') "First day of current mo

转,Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数

关于处理小数点位数的几个oracle函数() 1. 取四舍五入的几位小数 select round(1.2345, 3) from dual; 结果:1.235 2. 保留两位小数,只舍 select trunc(1.2345, 2) from dual; 结果:1.23 select trunc(1.2399, 2) from dual; 结果:1.23 3.取整数 返回大于或等于x的最大整数: SQL> select ceil(23.33) from dual; 结果: 24 返回等于或小于

ORACLE查询并删除重复记录

查询及删除重复记录的SQL语句 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select   peopleId from   people group by   peopleId having count(peopleId) > 1) 2.删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录delete from people where

ORACLE查询数据库的锁表情况

  查询数据库的锁表情况语句如下: SELECT p.spid,a.serial#, c.object_name,b.session_id,b.oracle_username,b.os_user_name FROM v$process p,v$session a, v$locked_object b,all_objects c WHERE p.addr=a.paddr AND a.process=b.process AND c.object_id=b.object_id 如果表因为某些情况出现死