日期:2014-05-16  浏览次数:20518 次

orcale 常用练习

(ORACLE-E-001)员工信息综合查询

1. 用 sqlplus 连接数据库时,为什么会出Oracle not available 错误?

oracle server(即通常所说的数据库)是否启动,ORACLE_SID 是否正确
设置。


2. 找出员工的姓中(last_name)第三个字母是a 的员工名字

select last_name from s_emp where last_name like '__a%';
3. 找出员工名字中含有a 和e 的

select first_name from s_emp where first_name like '%a%' and
first_name like '%e%';

比较:
select first_name from s_emp where first_name like '%a%e%';
4. 找出所有有提成的员工,列出名字、工资、提出,显示结果按工资从小到大,提成从小
到大

select first_name , salary , commission_pct from s_emp where
commission_pct is not null order by salary desc ,
commission_pct;

5. 42 部门有哪些职位

select distinct title from s_emp where dept_id = 42
6. 哪些部门不是Sales 部

select id , name ,region_id from s_dept where name <> 'Sales'


7. 显示工资不在1000 到1550 之间的员工信息:名字、工资,按工资从大到小排序。

?

select first_name , salary from s_emp where salary not between
1000 and 1550 order by salary desc

8. 显示职位为Stock Clerk 和Sales Representative,年薪在14400 和17400 之间的
员工的信息:名字、职位、年薪。

select first_name , title , salary*12 ann_sal from s_emp where
title in ('Stock Clerk', 'Sales Representative' and salary between 1200
and 1450;

9. 解释select id ,commission_pct from s_emp where commission_pct is null
和select id , commission_pct from s_emp where commission_pct = null

is null 判断是否为空,=null 判断某个值是否等于null,null = null 和null <>
null 都为false。

10. select 语句的输出结果为
select * from s_dept;
select * from s_emp;
select * from s_region;
select * from s_customer;
……
当前用户有多少张表,结果集有多少条记录。

select 'select * from '||table_name||';' from user_tables;


11. 判断select first_name , dept_id from s_emp where salary > '1450'是否抱错,为什么?

隐式数据类型转换。