码迷,mamicode.com
首页 > 数据库 > 详细

oracle第二天

时间:2016-07-01 01:06:31      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:

集合运算

SQL> host cls

SQL> /*
SQL> 查询部门号是10和20的员工信息
SQL> 1. select * from emp where deptno in (10,20);
SQL> 2. select * from emp where deptno=10 or deptno=20;
SQL> 3. 集合运算
SQL> select * from emp where deptno=10
SQL> 加上
SQL> select * from emp where deptno=20;
SQL> */
SQL> select * from emp where deptno=10
2 union
3 select * from emp where deptno=20;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7876 ADAMS CLERK 7788 13-7月 -87 1100 20
7902 FORD ANALYST 7566 03-12月-81 3000 20
7934 MILLER CLERK 7782 23-1月 -82 1300 10

已选择8行。

SQL> select deptno,job,sum(sal) from emp group by rollup(deptno,job);

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
10 MANAGER 2450
10 PRESIDENT 5000
10 8750
20 CLERK 1900
20 ANALYST 6000
20 MANAGER 2975
20 10875
30 CLERK 950
30 MANAGER 2850
30 SALESMAN 5600

DEPTNO JOB SUM(SAL)
---------- --------- ----------
30 9400
29025

已选择13行。

SQL> select deptno,job,sum(sal) from emp group by deptno,job
2 union
3 select deptno,sum(sal) from emp group by deptno
4 union
5 select sum(sal) from emp;
select deptno,sum(sal) from emp group by deptno
*
第 3 行出现错误:
ORA-01789: 查询块具有不正确的结果列数


SQL> /*
SQL> 注意的问题
SQL> 1. 参与运算的各个集合必须列数相同 且类型一致
SQL> 2. 采用第一个集合的表头作为最后的表头
SQL> 3. 如果排序,必须 在每个集合后使用相同order by
SQL> 4. 括号
SQL> */
SQL> select deptno,job,sum(sal) from emp group by deptno,job
2 union
3 select deptno,to_char(null),sum(sal) from emp group by deptno
4 union
5 select to_number(null),to_char(null),sum(sal) from emp;

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
10 MANAGER 2450
10 PRESIDENT 5000
10 8750
20 ANALYST 6000
20 CLERK 1900
20 MANAGER 2975
20 10875
30 CLERK 950
30 MANAGER 2850
30 SALESMAN 5600

DEPTNO JOB SUM(SAL)
---------- --------- ----------
30 9400
29025

已选择13行。

SQL> break on deptno skip 2
SQL> select deptno,job,sum(sal) from emp group by deptno,job
2 union
3 select deptno,to_char(null),sum(sal) from emp group by deptno
4 union
5 select to_number(null),to_char(null),sum(sal) from emp;

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
MANAGER 2450
PRESIDENT 5000
8750


20 ANALYST 6000
CLERK 1900
MANAGER 2975
10875

DEPTNO JOB SUM(SAL)
---------- --------- ----------

30 CLERK 950
MANAGER 2850
SALESMAN 5600
9400


29025

已选择13行。

SQL> break on null
SQL> host cls

SQL> select deptno,job,sum(sal) from emp group by rollup(deptno,job);

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
10 MANAGER 2450
10 PRESIDENT 5000
10 8750
20 CLERK 1900
20 ANALYST 6000
20 MANAGER 2975
20 10875
30 CLERK 950
30 MANAGER 2850
30 SALESMAN 5600

DEPTNO JOB SUM(SAL)
---------- --------- ----------
30 9400
29025

已选择13行。

SQL> set timing on
SQL> select deptno,job,sum(sal) from emp group by rollup(deptno,job);

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
10 MANAGER 2450
10 PRESIDENT 5000
10 8750
20 CLERK 1900
20 ANALYST 6000
20 MANAGER 2975
20 10875
30 CLERK 950
30 MANAGER 2850
30 SALESMAN 5600

DEPTNO JOB SUM(SAL)
---------- --------- ----------
30 9400
29025

已选择13行。

已用时间: 00: 00: 00.00
SQL> select deptno,job,sum(sal) from emp group by deptno,job
2 union
3 select deptno,to_char(null),sum(sal) from emp group by deptno
4 union
5 select to_number(null),to_char(null),sum(sal) from emp;

DEPTNO JOB SUM(SAL)
---------- --------- ----------
10 CLERK 1300
10 MANAGER 2450
10 PRESIDENT 5000
10 8750
20 ANALYST 6000
20 CLERK 1900
20 MANAGER 2975
20 10875
30 CLERK 950
30 MANAGER 2850
30 SALESMAN 5600

DEPTNO JOB SUM(SAL)
---------- --------- ----------
30 9400
29025

已选择13行。

已用时间: 00: 00: 00.01
SQL> --优化6: 尽量不要使用集合运算
SQL> set timing off
SQL> host cls

SQL> --交集
SQL> select ename,sal from emp
2 where sal between 700 and 1300
3 INTERSECT
4 select ename,sal from emp
5 where sal between 1201 and 1400;

ENAME SAL
---------- -----
MARTIN 1250
MILLER 1300
WARD 1250

SQL> select ename,sal from emp
2 where sal between 700 and 1300
3 minus
4 select ename,sal from emp
5 where sal between 1201 and 1400;

ENAME SAL
---------- -----
ADAMS 1100
JAMES 950
SMITH 800

SQL> spool off

解锁和改密码

1. 管理员登录
c:\>sqlplus sys/你的密码 as sysdba (密码认证)
c:\>sqlplus / as sysdba (主机认证 优先)


2. 解锁
SQL>alter user scott account unlock;

3. 改密码
SQL>alter user scott identified by 新密码;

课堂练习

SQL> -- rownum 行号 伪列
SQL> select rownum, empno,ename,sal
2 from emp;

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
1 7369 SMITH 800
2 7499 ALLEN 1600
3 7521 WARD 1250
4 7566 JONES 2975
5 7654 MARTIN 1250
6 7698 BLAKE 2850
7 7782 CLARK 2450
8 7788 SCOTT 3000
9 7839 KING 5000
10 7844 TURNER 1500
11 7876 ADAMS 1100

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
12 7900 JAMES 950
13 7902 FORD 3000
14 7934 MILLER 1300

已选择14行。

SQL> select rownum,empno,ename,sal
2 from emp
3 where rownum<=3
4 order by sal desc;

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
2 7499 ALLEN 1600
3 7521 WARD 1250
1 7369 SMITH 800

SQL> /*
SQL> 关于行号
SQL> 1. 按照默认的顺序生成
SQL> 2. rownum只能使用< <=, 不能> >=*/
SQL> select rownum, empno,ename,sal
2 from emp
3 order by sal desc;

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
9 7839 KING 5000
13 7902 FORD 3000
8 7788 SCOTT 3000
4 7566 JONES 2975
6 7698 BLAKE 2850
7 7782 CLARK 2450
2 7499 ALLEN 1600
10 7844 TURNER 1500
14 7934 MILLER 1300
3 7521 WARD 1250
5 7654 MARTIN 1250

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
11 7876 ADAMS 1100
12 7900 JAMES 950
1 7369 SMITH 800

已选择14行。

SQL> host cls

SQL> --第一题
SQL> select rownum,empno,ename,sal
2 from (select * from emp order by sal desc)
3 where rownum<=3;

ROWNUM EMPNO ENAME SAL
---------- ---------- ---------- -----
1 7839 KING 5000
2 7788 SCOTT 3000
3 7902 FORD 3000

SQL> select rownum,empno,ename,sal
2 from emp
3 where rownum>=5 and rownum<=8;

未选定行

SQL> select *
2 from (select rownum r,e1.*
3 from (select * from emp order by sal) e1
4 where rownum <=8
5 )
6 where r >=5;

R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- ---------- --------- ---------- -------------- ----- ---------- ----------
5 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
6 7934 MILLER CLERK 7782 23-1月 -82 1300 10
7 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
8 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30

SQL> host cls

SQL> --第二题
SQL> select e.empno,e.ename,e.sal,d.avgsal
2 from emp e,(select deptno,avg(sal) avgsal from emp group by deptno) d
3 where e.deptno=d.deptno and e.sal>d.avgsal;

EMPNO ENAME SAL AVGSAL
---------- ---------- ----- ----------
7698 BLAKE 2850 1566.66667
7499 ALLEN 1600 1566.66667
7902 FORD 3000 2175
7788 SCOTT 3000 2175
7566 JONES 2975 2175
7839 KING 5000 2916.66667

已选择6行。

SQL> --相关子查询: 将主查询中的某个值 作为参数传递给子查询
SQL> select empno,ename,sal,(select avg(sal) from emp where deptno=e.deptno) avgsal
2 from emp e
3 where sal> (select avg(sal) from emp where deptno=e.deptno);

EMPNO ENAME SAL AVGSAL
---------- ---------- ----- ----------
7499 ALLEN 1600 1566.66667
7566 JONES 2975 2175
7698 BLAKE 2850 1566.66667
7788 SCOTT 3000 2175
7839 KING 5000 2916.66667
7902 FORD 3000 2175

已选择6行。

SQL> host cls

SQL> --第三题
SQL> select hiredate from emp;

HIREDATE
--------------
17-12月-80
20-2月 -81
22-2月 -81
02-4月 -81
28-9月 -81
01-5月 -81
09-6月 -81
13-7月 -87
17-11月-81
08-9月 -81
13-7月 -87

HIREDATE
--------------
03-12月-81
03-12月-81
23-1月 -82

已选择14行。

SQL> /*
SQL> HIREDATE count81=0
SQL> ------------------------
SQL> 17-12月-80 0
SQL> 20-2月 -81 1
SQL> 22-2月 -81 1
SQL> 02-4月 -81 1
SQL> 28-9月 -81 1
SQL> 01-5月 -81 1
SQL> 09-6月 -81 1
SQL> 13-7月 -87 0
SQL> 17-11月-81 1
SQL> 08-9月 -81 1
SQL> 13-7月 -87 0
SQL> 03-12月-81 1
SQL> 03-12月-81 1
SQL> 23-1月 -82 0
SQL> ===========================
SQL> 10
SQL>
SQL> sum(if 是81年 then +1 else +0)
SQL> */
SQL> host cls

SQL> --组函数 行转列 wm_concat
SQL> select deptno,wm_concat(ename) names
2 from emp
3 group by deptno;

DEPTNO
----------
NAMES
------------------------------------------------------------------------------------------------------------------------
10
CLARK,KING,MILLER

20
SMITH,FORD,ADAMS,SCOTT,JONES

30
ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD

SQL> col names for a40
SQL> select deptno,wm_concat(ename) names
2 from emp
3 group by deptno;

DEPTNO NAMES
---------- ----------------------------------------
10 CLARK,KING,MILLER
20 SMITH,FORD,ADAMS,SCOTT,JONES
30 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD

SQL> spool off

子查询

SQL> host cls

SQL> --查询工资比SCOTT高的员工信息
SQL> --1. SCOTT的工资
SQL> select sal from emp where ename=‘SCOTT‘;

SAL
----------
3000

SQL> --2.比3000高的
SQL> set linesize 120
SQL> col sal for 9999
SQL> select * from emp where sal > 3000;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7839 KING PRESIDENT 17-11月-81 5000 10

SQL> --解决的问题:不能一步求解
SQL> select *
2 from emp
3 where sal > (select sal
4 from emp
5 where ename=‘SCOTT‘);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7839 KING PRESIDENT 17-11月-81 5000 10

SQL> /*
SQL> 注意的问题
SQL> 1. 括号
SQL> 2. 合理的书写风格
SQL> 3. 可以主查询的where select from having后面放置子查询
SQL> 4. 不可以在主查询的group by后面放置子查询
SQL> 5. 强调from后面的子查询
SQL> 6. 主查询和子查询可以不是同一张表,只要子查询返回的结果 主查询可以使用即可
SQL> 7. 一般不在子查询使用order by,但在Top-N分析问题中 必须使用order by
SQL> 8. 一般先执行子查询,再执行主查询;但相关子查询除外
SQL> 9. 单行子查询只能使用单行操作符 多行子查询只能使用多行操作符
SQL> 10. 子查询中null
SQL> */
SQL> -- 3. 可以主查询的where select from having后面放置子查询
SQL> select ename,sal,(select job from emp where empno=7839) 一列
2 from emp;

ENAME SAL 一列
---------- ----- ---------
SMITH 800 PRESIDENT
ALLEN 1600 PRESIDENT
WARD 1250 PRESIDENT
JONES 2975 PRESIDENT
MARTIN 1250 PRESIDENT
BLAKE 2850 PRESIDENT
CLARK 2450 PRESIDENT
SCOTT 3000 PRESIDENT
KING 5000 PRESIDENT
TURNER 1500 PRESIDENT
ADAMS 1100 PRESIDENT

ENAME SAL 一列
---------- ----- ---------
JAMES 950 PRESIDENT
FORD 3000 PRESIDENT
MILLER 1300 PRESIDENT

已选择14行。

SQL> --5. 强调from后面的子查询
SQL> --查询员工的姓名和薪水
SQL> select *
2 from (select ename,sal from emp);

ENAME SAL
---------- -----
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100

ENAME SAL
---------- -----
JAMES 950
FORD 3000
MILLER 1300

已选择14行。

SQL> --查询员工的姓名 薪水 年薪
SQL> ed
已写入 file afiedt.buf

1 select *
2* from (select ename,sal,sal*12 annlsal from emp)
SQL> /

ENAME SAL ANNLSAL
---------- ----- ----------
SMITH 800 9600
ALLEN 1600 19200
WARD 1250 15000
JONES 2975 35700
MARTIN 1250 15000
BLAKE 2850 34200
CLARK 2450 29400
SCOTT 3000 36000
KING 5000 60000
TURNER 1500 18000
ADAMS 1100 13200

ENAME SAL ANNLSAL
---------- ----- ----------
JAMES 950 11400
FORD 3000 36000
MILLER 1300 15600

已选择14行。

SQL> --6. 主查询和子查询可以不是同一张表,只要子查询返回的结果 主查询可以使用即可
SQL> --查询部门名称为SALES的员工信息
SQL> select *
2 from emp
3 where deptno=(select deptno
4 from dept
5 where dname=‘SALES‘);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7900 JAMES CLERK 7698 03-12月-81 950 30

已选择6行。

SQL> select e.*
2 from emp e,dept d
3 where e.deptno=d.deptno and d.dname=‘SALES‘;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7900 JAMES CLERK 7698 03-12月-81 950 30

已选择6行。

SQL> --优化5:理论上,尽量使用多表查询
SQL> host cls

SQL> --in 在集合中
SQL> --查询部门名称是SALES和ACCOUNTING的员工
SQL> select *
2 from emp
3 where deptno in (select deptno from dept where dname=‘SALES‘ or dname=‘ACCOUNTING‘);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7839 KING PRESIDENT 17-11月-81 5000 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7900 JAMES CLERK 7698 03-12月-81 950 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10

已选择9行。

SQL> select e.*
2 from emp e,dept d
3 where e.deptno=d.deptno and (d.dname=‘SALES‘ or d.dname=‘ACCOUNTING‘);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7839 KING PRESIDENT 17-11月-81 5000 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7900 JAMES CLERK 7698 03-12月-81 950 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10

已选择9行。

SQL> --any: 和集合中 任意一个值比较
SQL> --查询工资比30号部门任意一个员工高的员工信息
SQL> select *\
2 ;
select *\
*
第 1 行出现错误:
ORA-00911: 无效字符


SQL> select *
2 from emp
3 where sal > any (select sal from emp where deptno=30);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7839 KING PRESIDENT 17-11月-81 5000 10
7902 FORD ANALYST 7566 03-12月-81 3000 20
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7876 ADAMS CLERK 7788 13-7月 -87 1100 20

已选择12行。

SQL> ed
已写入 file afiedt.buf

1 select *
2 from emp
3* where sal > (select min(sal) from emp where deptno=30)
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7876 ADAMS CLERK 7788 13-7月 -87 1100 20
7902 FORD ANALYST 7566 03-12月-81 3000 20

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7934 MILLER CLERK 7782 23-1月 -82 1300 10

已选择12行。

SQL> --all:和集合的所有值比较
SQL> --查询工资比30号部门所有员工高的员工信息
SQL> select *
2 from emp
3 where sal > all (select sal from emp where deptno=30);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7902 FORD ANALYST 7566 03-12月-81 3000 20

SQL> ed
已写入 file afiedt.buf

1 select *
2 from emp
3* where sal > (select max(sal) from emp where deptno=30)
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7902 FORD ANALYST 7566 03-12月-81 3000 20

SQL> host cls

SQL> --多行子查询中null
SQL> --查询不是老板的员工信息
SQL> select * from emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7782 CLARK MANAGER 7839 09-6月 -81 2450 10
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7839 KING PRESIDENT 17-11月-81 5000 10
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7876 ADAMS CLERK 7788 13-7月 -87 1100 20

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7900 JAMES CLERK 7698 03-12月-81 950 30
7902 FORD ANALYST 7566 03-12月-81 3000 20
7934 MILLER CLERK 7782 23-1月 -82 1300 10

已选择14行。

SQL> --是老板的员工
SQL> select *
2 from emp
3 where empno in (select mgr from emp);

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7902 FORD ANALYST 7566 03-12月-81 3000 20
7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
7839 KING PRESIDENT 17-11月-81 5000 10
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7782 CLARK MANAGER 7839 09-6月 -81 2450 10

已选择6行。

SQL> ed
已写入 file afiedt.buf

1 select *
2 from emp
3* where empno not in (select mgr from emp)
SQL> /

未选定行

SQL> ed
已写入 file afiedt.buf

1 select *
2 from emp
3* where empno not in (select mgr from emp where mgr is not null)
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10
7369 SMITH CLERK 7902 17-12月-80 800 20
7876 ADAMS CLERK 7788 13-7月 -87 1100 20
7900 JAMES CLERK 7698 03-12月-81 950 30

已选择8行。

SQL> spool off

处理数据

SQL> host cls

SQL> select count(*) Total,
2 sum(decode(to_char(hiredate,‘RR‘),‘80‘,1,0)) "1980",
3 sum(decode(to_char(hiredate,‘RR‘),‘81‘,1,0)) "1981",
4 sum(decode(to_char(hiredate,‘RR‘),‘82‘,1,0)) "1982",
5 sum(decode(to_char(hiredate,‘RR‘),‘87‘,1,0)) "1987"
6 from emp;

TOTAL 1980 1981 1982 1987
---------- ---------- ---------- ---------- ----------
14 1 10 1 2

SQL> host cls

SQL> /*
SQL> SQL类型
SQL> 1. DML(Data Manipulation Lanuage 数据操作语言): select insert update delete
SQL> 2. DDL(Data Definition Language 数据定义语言): create/alter/drop/truncate table
SQL> create/drop view/sequence/index/synonym
SQL> 3. DCL(Data Control Language 数据控制语言): commit rollback
SQL> */
SQL> host cls

SQL> --插入数据 insert
SQL> insert into emp(empno,ename,sal ,deptno)
2 values(1001,‘Tom‘,6000,20);

已创建 1 行。

SQL> --隐式/显式插入null
SQL> --地址符 &
SQL> insert into emp(empno,ename,sal,deptno)
2 values(&empno,&ename,&sal,&deptno);
输入 empno 的值: 1002
输入 ename 的值: ‘Mary‘
输入 sal 的值: 5000
输入 deptno 的值: 10
原值 2: values(&empno,&ename,&sal,&deptno)
新值 2: values(1002,‘Mary‘,5000,10)

已创建 1 行。

SQL> /
输入 empno 的值: 1003
输入 ename 的值: ‘Mike‘
输入 sal 的值: 6000
输入 deptno 的值: 30
原值 2: values(&empno,&ename,&sal,&deptno)
新值 2: values(1003,‘Mike‘,6000,30)

已创建 1 行。

SQL> ed
已写入 file afiedt.buf

1 insert into emp(empno,ename,sal,deptno)
2* values(&empno,‘&ename‘,&sal,&deptno)
SQL> /
输入 empno 的值: 1004
输入 ename 的值: Jerry
输入 sal 的值: 5000
输入 deptno 的值: 10
原值 2: values(&empno,‘&ename‘,&sal,&deptno)
新值 2: values(1004,‘Jerry‘,5000,10)

已创建 1 行。

SQL> host ls

SQL> host cls

SQL> select empno,ename,&t
2 from emp;
输入 t 的值: sal
原值 1: select empno,ename,&t
新值 1: select empno,ename,sal

EMPNO ENAME SAL
---------- ---------- ----------
1001 Tom 6000
1002 Mary 5000
1003 Mike 6000
1004 Jerry 5000
7369 SMITH 800
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450

EMPNO ENAME SAL
---------- ---------- ----------
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 1100
7900 JAMES 950
7902 FORD 3000
7934 MILLER 1300

已选择18行。

SQL> /
输入 t 的值: deptno
原值 1: select empno,ename,&t
新值 1: select empno,ename,deptno

EMPNO ENAME DEPTNO
---------- ---------- ----------
1001 Tom 20
1002 Mary 10
1003 Mike 30
1004 Jerry 10
7369 SMITH 20
7499 ALLEN 30
7521 WARD 30
7566 JONES 20
7654 MARTIN 30
7698 BLAKE 30
7782 CLARK 10

EMPNO ENAME DEPTNO
---------- ---------- ----------
7788 SCOTT 20
7839 KING 10
7844 TURNER 30
7876 ADAMS 20
7900 JAMES 30
7902 FORD 20
7934 MILLER 10

已选择18行。

SQL> select *
2 from &t;
输入 t 的值: dept
原值 2: from &t
新值 2: from dept

DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

SQL> rollback;

回退已完成。

SQL> host cls

SQL> --批处理
SQL> create table emp10 as select * from emp where 1=2;

表已创建。

SQL> desc emp10
名称 是否为空? 类型
----------------------------------------- -------- ----------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

SQL> select * from emp10;

未选定行

SQL> --一次性从emp中 将所有10号部门的员工插入到emp10
SQL> insert into emp10
2 select * from emp where deptno=10;

已创建3行。

SQL> select * from emp10;

EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- -------------- ---------- ----------
DEPTNO
----------
7782 CLARK MANAGER 7839 09-6月 -81 2450
10

7839 KING PRESIDENT 17-11月-81 5000
10

7934 MILLER CLERK 7782 23-1月 -82 1300
10

SQL> set linesize 120
SQL> col sal for 9999
SQL> host cls

SQL> --更新数据
SQL> --删除数据
SQL> /*
SQL> delete 和truncate的区别
SQL> 1. delete逐条删除 truncate 先摧毁表 再重建
SQL> 2. **** delete 是DML(可以回滚),truncate是DDL(不可以回滚)
SQL> 3. delete不会释放空间 truncate会
SQL> 4. delete会产生碎片 truncate不会
SQL> 5. delete可以闪回,truncate不可以
SQL> */
SQL> set feedback off
SQL> @c:\sql.sql
SQL> select count(*) from testdelete;

COUNT(*)
----------
5000
SQL> set timing on
SQL> delete from testdelete;
已用时间: 00: 00: 00.04
SQL> set timing off
SQL> drop table testdelete purge;
SQL> @c:\sql.sql
SQL> select count(*) from testdelete;

COUNT(*)
----------
5000
SQL> set timing on
SQL> truncate table testdelete;
已用时间: 00: 00: 07.87
SQL> set timing off
SQL> host cls

SQL> /*
SQL> Oracle中的事务
SQL> 1. 起始标志: DML语句
SQL> 2. 结束标志: 提交: 显式提交 commit
SQL> 隐式提交 正常退出exit ,DDL语句
SQL> 回滚: 显式 rollback
SQL> 隐式 掉电,宕机,非正常退出
SQL> */
SQL> --保存点
SQL> create table testsavepoint
2 (tid number,tname varchar2(20));
SQL> set feedback on
SQL> insert into testsavepoint values(1,‘Tom‘);

已创建 1 行。

SQL> insert into testsavepoint values(2,‘Mary‘);

已创建 1 行。

SQL> savepoint a;

保存点已创建。

SQL> insert into testsavepoint values(3,‘Moke‘);

已创建 1 行。

SQL> select * from testsavepoint;

TID TNAME
---------- --------------------
1 Tom
2 Mary
3 Moke

已选择3行。

SQL> rollback to savepoint a;

回退已完成。

SQL> select * from testsavepoint;

TID TNAME
---------- --------------------
1 Tom
2 Mary

已选择2行。

SQL> commit;

提交完成。

SQL> spool off

创建和管理表

SQL> host cls

SQL> create table test1
2 (tid number,
3 tname varchar2(20),
4 hiredate date default sysdate);

表已创建。

SQL> insert into test1(tid,tname) values(1,‘Tom‘);

已创建 1 行。

SQL> select * from test1;

TID TNAME HIREDATE
---------- -------------------- --------------
1 Tom 20-6月 -13

已选择 1 行。

SQL> host cls

SQL> --行地址
SQL> select rowid,empno,ename from emp;

ROWID EMPNO ENAME
------------------ ---------- ----------
AAANIwAAEAAAAAeAAA 7369 SMITH
AAANIwAAEAAAAAeAAB 7499 ALLEN
AAANIwAAEAAAAAeAAC 7521 WARD
AAANIwAAEAAAAAeAAD 7566 JONES
AAANIwAAEAAAAAeAAE 7654 MARTIN
AAANIwAAEAAAAAeAAF 7698 BLAKE
AAANIwAAEAAAAAeAAG 7782 CLARK
AAANIwAAEAAAAAeAAH 7788 SCOTT
AAANIwAAEAAAAAeAAI 7839 KING
AAANIwAAEAAAAAeAAJ 7844 TURNER
AAANIwAAEAAAAAeAAK 7876 ADAMS

ROWID EMPNO ENAME
------------------ ---------- ----------
AAANIwAAEAAAAAeAAL 7900 JAMES
AAANIwAAEAAAAAeAAM 7902 FORD
AAANIwAAEAAAAAeAAN 7934 MILLER

已选择14行。

SQL> --保存20号部门的员工
SQL> create table emp20
2 as
3 select * from emp where deptno=20;

表已创建。

SQL> select * from emp20;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ---------- ----------
7369 SMITH CLERK 7902 17-12月-80 800 20
7566 JONES MANAGER 7839 02-4月 -81 2975 20
7788 SCOTT ANALYST 7566 13-7月 -87 3000 20
7876 ADAMS CLERK 7788 13-7月 -87 1100 20
7902 FORD ANALYST 7566 03-12月-81 3000 20

已选择5行。

SQL> --创建表: 员工号 姓名 月薪 年薪 部门名称
SQL> create table empinfo
2 as
3 select e.empno,e.ename,e.sal,e.sal*12 annlsal,d.dname
4 from emp e,dept d
5 where e.deptno=d.deptno;

表已创建。

SQL> select * from empinfo;

EMPNO ENAME SAL ANNLSAL DNAME
---------- ---------- ----- ---------- --------------
7369 SMITH 800 9600 RESEARCH
7499 ALLEN 1600 19200 SALES
7521 WARD 1250 15000 SALES
7566 JONES 2975 35700 RESEARCH
7654 MARTIN 1250 15000 SALES
7698 BLAKE 2850 34200 SALES
7782 CLARK 2450 29400 ACCOUNTING
7788 SCOTT 3000 36000 RESEARCH
7839 KING 5000 60000 ACCOUNTING
7844 TURNER 1500 18000 SALES
7876 ADAMS 1100 13200 RESEARCH

EMPNO ENAME SAL ANNLSAL DNAME
---------- ---------- ----- ---------- --------------
7900 JAMES 950 11400 SALES
7902 FORD 3000 36000 RESEARCH
7934 MILLER 1300 15600 ACCOUNTING

已选择14行。

SQL> host cls

SQL> --修改表: 追加新列 修改列 删除列 重名列
SQL> desc test1
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
TID NUMBER
TNAME VARCHAR2(20)
HIREDATE DATE

SQL> alter table test1 add image blob;

表已更改。

SQL> desc test1
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
TID NUMBER
TNAME VARCHAR2(20)
HIREDATE DATE
IMAGE BLOB

SQL> alter table test1 modify tname varchar2(40);

表已更改。

SQL> desc test1
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
TID NUMBER
TNAME VARCHAR2(40)
HIREDATE DATE
IMAGE BLOB

SQL> alter table drop column image;
alter table drop column image
*
第 1 行出现错误:
ORA-00903: 表名无效


SQL> alter table test1 drop column image;

表已更改。

SQL> desc test1
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
TID NUMBER
TNAME VARCHAR2(40)
HIREDATE DATE

SQL> alter table test1 rename tname to username;
alter table test1 rename tname to username
*
第 1 行出现错误:
ORA-14155: 缺失 PARTITION 或 SUBPARTITION 关键字


SQL> alter table test1 rename column tname to username;

表已更改。

SQL> desc test1
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
TID NUMBER
USERNAME VARCHAR2(40)
HIREDATE DATE

SQL> host cls

SQL> -- 删除表
SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
DEPT TABLE
TESTSAVEPOINT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
EMP10 TABLE
TESTDELETE TABLE
TEST1 TABLE
EMP20 TABLE
EMPINFO TABLE

已选择10行。

SQL> drop table test1;

表已删除。

SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$UKc1E0vyQ0C1ZcDR8cUI4w==$0 TABLE
DEPT TABLE
TESTSAVEPOINT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
EMP10 TABLE
TESTDELETE TABLE
EMP20 TABLE
EMPINFO TABLE

已选择10行。

SQL> --Oracle的回收站
SQL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST1 BIN$UKc1E0vyQ0C1ZcDR8cUI4w==$0 TABLE 2013-06-20:15:23:20
SQL> purge recyclebin;

回收站已清空。

SQL> show recyclebin
SQL> --drop table test1 purge; --> 不经过回收站直接删除
SQL> select * from TESTSAVEPOINT;

TID TNAME
---------- --------------------
1 Tom
2 Mary

已选择2行。

SQL> host cls

SQL> drop table TESTSAVEPOINT;

表已删除。

SQL> show recyclebin
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TESTSAVEPOINT BIN$b9zRUzdaQfuXXqNhykffVA==$0 TABLE 2013-06-20:15:26:10
SQL> select * from TESTSAVEPOINT;
select * from TESTSAVEPOINT
*
第 1 行出现错误:
ORA-00942: 表或视图不存在


SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$b9zRUzdaQfuXXqNhykffVA==$0 TABLE
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
EMP10 TABLE
TESTDELETE TABLE
EMP20 TABLE
EMPINFO TABLE

已选择9行。

SQL> select * from BIN$b9zRUzdaQfuXXqNhykffVA==$0;
select * from BIN$b9zRUzdaQfuXXqNhykffVA==$0
*
第 1 行出现错误:
ORA-00933: SQL 命令未正确结束


SQL> select * from "BIN$b9zRUzdaQfuXXqNhykffVA==$0";

TID TNAME
---------- --------------------
1 Tom
2 Mary

已选择2行。

SQL> --注意: 管理员没有回收站
SQL> host cls

SQL> --检查性约束
SQL> create table test2
2 (tid number,
3 tname varchar2(20),
4 gender varchar2(4) check (gender in (‘男‘,‘女‘)),
5 sal number check (sal > 0)
6 );

表已创建。

SQL> insert into test2 values(1,‘Tom‘, ‘男‘, 5000);

已创建 1 行。

SQL> insert into test2 values(2,‘Tom‘, ‘啊‘, 5000);
insert into test2 values(2,‘Tom‘, ‘啊‘, 5000)
*
第 1 行出现错误:
ORA-02290: 违反检查约束条件 (SCOTT.SYS_C005636)


SQL> update test2 set gender=‘啊‘ where tid=1;
update test2 set gender=‘啊‘ where tid=1
*
第 1 行出现错误:
ORA-02290: 违反检查约束条件 (SCOTT.SYS_C005636)


SQL> host cls

SQL> create table myperson
2 (pid varchar2(18) constraint myperson_PK primary key,
3 pname varchar2(40) constraint myperson_Name_notnull not null,
4 gender varchar2(4) constraint myperson_Gender check (gender in (‘男‘,‘女‘)),
5 email varchar2(40) constraint myperson_Email_unique unique
6 constraint myperson_Email_notnull not null,
7 deptno number constraint myperson_FK references dept(deptno) ON DELETE CASCADE
8 );

表已创建。

SQL> insert into myperson values(‘p001‘,‘Tom‘,‘男‘,‘tom@126.com‘,10);

已创建 1 行。

SQL> insert into myperson values(‘p002‘,‘Tom‘,‘男‘,‘tom@126.com‘,10);
insert into myperson values(‘p002‘,‘Tom‘,‘男‘,‘tom@126.com‘,10)
*
第 1 行出现错误:
ORA-00001: 违反唯一约束条件 (SCOTT.MYPERSON_EMAIL_UNIQUE)


SQL>
SQL> spool off

其它数据库对象

SQL> host cls

SQL> --视图
SQL> create view empview
2 as
3 select e.empno,e.ename,e.sal,e.sal*12 annlsal,d.dname
4 from emp e,dept d
5 where e.deptno=d.deptno;
create view empview
*
第 1 行出现错误:
ORA-01031: 权限不足


SQL> /

视图已创建。

SQL> select * from tab;

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BIN$b9zRUzdaQfuXXqNhykffVA==$0 TABLE
MYPERSON TABLE
TEST2 TABLE
EMPVIEW VIEW
DEPT TABLE
EMP TABLE
BONUS TABLE
SALGRADE TABLE
EMP10 TABLE
TESTDELETE TABLE
EMP20 TABLE

TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
EMPINFO TABLE

已选择12行。

SQL> select * from EMPVIEW;

EMPNO ENAME SAL ANNLSAL DNAME
---------- ---------- ----- ---------- --------------
7369 SMITH 800 9600 RESEARCH
7499 ALLEN 1600 19200 SALES
7521 WARD 1250 15000 SALES
7566 JONES 2975 35700 RESEARCH
7654 MARTIN 1250 15000 SALES
7698 BLAKE 2850 34200 SALES
7782 CLARK 2450 29400 ACCOUNTING
7788 SCOTT 3000 36000 RESEARCH
7839 KING 5000 60000 ACCOUNTING
7844 TURNER 1500 18000 SALES
7876 ADAMS 1100 13200 RESEARCH

EMPNO ENAME SAL ANNLSAL DNAME
---------- ---------- ----- ---------- --------------
7900 JAMES 950 11400 SALES
7902 FORD 3000 36000 RESEARCH
7934 MILLER 1300 15600 ACCOUNTING

已选择14行。

SQL> desc EMPVIEW
名称 是否为空? 类型
----------------------------------------------------------------- -------- --------------------------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
SAL NUMBER(7,2)
ANNLSAL NUMBER
DNAME VARCHAR2(14)

SQL> create or replace view empview
2 as
3 select e.empno,e.ename,e.sal,e.sal*12 annlsal,d.dname
4 from emp e,dept d
5 where e.deptno=d.deptno
6 with read only
7 ;

视图已创建。

SQL> host cls

SQL> --序列
SQL> --sequence
SQL> create sequence myseq;

序列已创建。

SQL> create table tableA(tid number,tname varchar2(20));

表已创建。

SQL> select myseq.currval from dual;
select myseq.currval from dual
*
第 1 行出现错误:
ORA-08002: 序列 MYSEQ.CURRVAL 尚未在此会话中定义


SQL> select myseq.nextval from dual;

NEXTVAL
----------
1

已选择 1 行。

SQL> select myseq.currval from dual;

CURRVAL
----------
1

已选择 1 行。

SQL> insert into tableA values(myseq.nextval,‘aaa‘ );

已创建 1 行。

SQL> /

已创建 1 行。

SQL> /

已创建 1 行。

SQL> commit;

提交完成。

SQL> select * from tableA;

TID TNAME
---------- --------------------
2 aaa
3 aaa
4 aaa

已选择3行。

SQL> /*
SQL> 序列的不连续
SQL> 1. 序列是公有对象
SQL> 2. 掉电
SQL> 3. 回滚
SQL> */
SQL> insert into tableA values(myseq.nextval,‘aaa‘ );

已创建 1 行。

SQL> /

已创建 1 行。

SQL> rollback;

回退已完成。

SQL> insert into tableA values(myseq.nextval,‘aaa‘ );

已创建 1 行。

SQL> select * from tableA;

TID TNAME
---------- --------------------
2 aaa
3 aaa
4 aaa
7 aaa

已选择4行。

SQL> host cls

SQL> --索引
SQL> --index
SQL> create index myindex on emp(deptno);

索引已创建。

SQL> host cls

SQL> --同义词 --> 别名
SQL> select count(*)
2 from hr.EMPLOYEES;
from hr.EMPLOYEES
*
第 2 行出现错误:
ORA-00942: 表或视图不存在


SQL> /

COUNT(*)
----------
107

已选择 1 行。

SQL> create synonym hremp for hr.EMPLOYEES;
create synonym hremp for hr.EMPLOYEES
*
第 1 行出现错误:
ORA-01031: 权限不足


SQL> /

同义词已创建。

SQL> select * from hremp;

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
198 Donald OConnell DOCONNEL 650.507.9833 21-6月 -99
SH_CLERK 2600 124 50

199 Douglas Grant DGRANT 650.507.9844 13-1月 -00
SH_CLERK 2600 124 50

200 Jennifer Whalen JWHALEN 515.123.4444 17-9月 -87
AD_ASST 4400 101 10

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
201 Michael Hartstein MHARTSTE 515.123.5555 17-2月 -96
MK_MAN 13000 100 20

202 Pat Fay PFAY 603.123.6666 17-8月 -97
MK_REP 6000 201 20

203 Susan Mavris SMAVRIS 515.123.7777 07-6月 -94
HR_REP 6500 101 40

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
204 Hermann Baer HBAER 515.123.8888 07-6月 -94
PR_REP 10000 101 70

205 Shelley Higgins SHIGGINS 515.123.8080 07-6月 -94
AC_MGR 12000 101 110

206 William Gietz WGIETZ 515.123.8181 07-6月 -94
AC_ACCOUNT 8300 205 110

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
100 Steven King SKING 515.123.4567 17-6月 -87
AD_PRES 24000 90

101 Neena Kochhar NKOCHHAR 515.123.4568 21-9月 -89
AD_VP 17000 100 90

102 Lex De Haan LDEHAAN 515.123.4569 13-1月 -93
AD_VP 17000 100 90

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
103 Alexander Hunold AHUNOLD 590.423.4567 03-1月 -90
IT_PROG 9000 102 60

104 Bruce Ernst BERNST 590.423.4568 21-5月 -91
IT_PROG 6000 103 60

105 David Austin DAUSTIN 590.423.4569 25-6月 -97
IT_PROG 4800 103 60

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
106 Valli Pataballa VPATABAL 590.423.4560 05-2月 -98
IT_PROG 4800 103 60

107 Diana Lorentz DLORENTZ 590.423.5567 07-2月 -99
IT_PROG 4200 103 60

108 Nancy Greenberg NGREENBE 515.124.4569 17-8月 -94
FI_MGR 12000 101 100

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
109 Daniel Faviet DFAVIET 515.124.4169 16-8月 -94
FI_ACCOUNT 9000 108 100

110 John Chen JCHEN 515.124.4269 28-9月 -97
FI_ACCOUNT 8200 108 100

111 Ismael Sciarra ISCIARRA 515.124.4369 30-9月 -97
FI_ACCOUNT 7700 108 100

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
112 Jose Manuel Urman JMURMAN 515.124.4469 07-3月 -98
FI_ACCOUNT 7800 108 100

113 Luis Popp LPOPP 515.124.4567 07-12月-99
FI_ACCOUNT 6900 108 100

114 Den Raphaely DRAPHEAL 515.127.4561 07-12月-94
PU_MAN 11000 100 30

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
115 Alexander Khoo AKHOO 515.127.4562 18-5月 -95
PU_CLERK 3100 114 30

116 Shelli Baida SBAIDA 515.127.4563 24-12月-97
PU_CLERK 2900 114 30

117 Sigal Tobias STOBIAS 515.127.4564 24-7月 -97
PU_CLERK 2800 114 30

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
118 Guy Himuro GHIMURO 515.127.4565 15-11月-98
PU_CLERK 2600 114 30

119 Karen Colmenares KCOLMENA 515.127.4566 10-8月 -99
PU_CLERK 2500 114 30

120 Matthew Weiss MWEISS 650.123.1234 18-7月 -96
ST_MAN 8000 100 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
121 Adam Fripp AFRIPP 650.123.2234 10-4月 -97
ST_MAN 8200 100 50

122 Payam Kaufling PKAUFLIN 650.123.3234 01-5月 -95
ST_MAN 7900 100 50

123 Shanta Vollman SVOLLMAN 650.123.4234 10-10月-97
ST_MAN 6500 100 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
124 Kevin Mourgos KMOURGOS 650.123.5234 16-11月-99
ST_MAN 5800 100 50

125 Julia Nayer JNAYER 650.124.1214 16-7月 -97
ST_CLERK 3200 120 50

126 Irene Mikkilineni IMIKKILI 650.124.1224 28-9月 -98
ST_CLERK 2700 120 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
127 James Landry JLANDRY 650.124.1334 14-1月 -99
ST_CLERK 2400 120 50

128 Steven Markle SMARKLE 650.124.1434 08-3月 -00
ST_CLERK 2200 120 50

129 Laura Bissot LBISSOT 650.124.5234 20-8月 -97
ST_CLERK 3300 121 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
130 Mozhe Atkinson MATKINSO 650.124.6234 30-10月-97
ST_CLERK 2800 121 50

131 James Marlow JAMRLOW 650.124.7234 16-2月 -97
ST_CLERK 2500 121 50

132 TJ Olson TJOLSON 650.124.8234 10-4月 -99
ST_CLERK 2100 121 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
133 Jason Mallin JMALLIN 650.127.1934 14-6月 -96
ST_CLERK 3300 122 50

134 Michael Rogers MROGERS 650.127.1834 26-8月 -98
ST_CLERK 2900 122 50

135 Ki Gee KGEE 650.127.1734 12-12月-99
ST_CLERK 2400 122 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
136 Hazel Philtanker HPHILTAN 650.127.1634 06-2月 -00
ST_CLERK 2200 122 50

137 Renske Ladwig RLADWIG 650.121.1234 14-7月 -95
ST_CLERK 3600 123 50

138 Stephen Stiles SSTILES 650.121.2034 26-10月-97
ST_CLERK 3200 123 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
139 John Seo JSEO 650.121.2019 12-2月 -98
ST_CLERK 2700 123 50

140 Joshua Patel JPATEL 650.121.1834 06-4月 -98
ST_CLERK 2500 123 50

141 Trenna Rajs TRAJS 650.121.8009 17-10月-95
ST_CLERK 3500 124 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
142 Curtis Davies CDAVIES 650.121.2994 29-1月 -97
ST_CLERK 3100 124 50

143 Randall Matos RMATOS 650.121.2874 15-3月 -98
ST_CLERK 2600 124 50

144 Peter Vargas PVARGAS 650.121.2004 09-7月 -98
ST_CLERK 2500 124 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
145 John Russell JRUSSEL 011.44.1344.429268 01-10月-96
SA_MAN 14000 .4 100 80

146 Karen Partners KPARTNER 011.44.1344.467268 05-1月 -97
SA_MAN 13500 .3 100 80

147 Alberto Errazuriz AERRAZUR 011.44.1344.429278 10-3月 -97
SA_MAN 12000 .3 100 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
148 Gerald Cambrault GCAMBRAU 011.44.1344.619268 15-10月-99
SA_MAN 11000 .3 100 80

149 Eleni Zlotkey EZLOTKEY 011.44.1344.429018 29-1月 -00
SA_MAN 10500 .2 100 80

150 Peter Tucker PTUCKER 011.44.1344.129268 30-1月 -97
SA_REP 10000 .3 145 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
151 David Bernstein DBERNSTE 011.44.1344.345268 24-3月 -97
SA_REP 9500 .25 145 80

152 Peter Hall PHALL 011.44.1344.478968 20-8月 -97
SA_REP 9000 .25 145 80

153 Christopher Olsen COLSEN 011.44.1344.498718 30-3月 -98
SA_REP 8000 .2 145 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
154 Nanette Cambrault NCAMBRAU 011.44.1344.987668 09-12月-98
SA_REP 7500 .2 145 80

155 Oliver Tuvault OTUVAULT 011.44.1344.486508 23-11月-99
SA_REP 7000 .15 145 80

156 Janette King JKING 011.44.1345.429268 30-1月 -96
SA_REP 10000 .35 146 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
157 Patrick Sully PSULLY 011.44.1345.929268 04-3月 -96
SA_REP 9500 .35 146 80

158 Allan McEwen AMCEWEN 011.44.1345.829268 01-8月 -96
SA_REP 9000 .35 146 80

159 Lindsey Smith LSMITH 011.44.1345.729268 10-3月 -97
SA_REP 8000 .3 146 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
160 Louise Doran LDORAN 011.44.1345.629268 15-12月-97
SA_REP 7500 .3 146 80

161 Sarath Sewall SSEWALL 011.44.1345.529268 03-11月-98
SA_REP 7000 .25 146 80

162 Clara Vishney CVISHNEY 011.44.1346.129268 11-11月-97
SA_REP 10500 .25 147 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
163 Danielle Greene DGREENE 011.44.1346.229268 19-3月 -99
SA_REP 9500 .15 147 80

164 Mattea Marvins MMARVINS 011.44.1346.329268 24-1月 -00
SA_REP 7200 .1 147 80

165 David Lee DLEE 011.44.1346.529268 23-2月 -00
SA_REP 6800 .1 147 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
166 Sundar Ande SANDE 011.44.1346.629268 24-3月 -00
SA_REP 6400 .1 147 80

167 Amit Banda ABANDA 011.44.1346.729268 21-4月 -00
SA_REP 6200 .1 147 80

168 Lisa Ozer LOZER 011.44.1343.929268 11-3月 -97
SA_REP 11500 .25 148 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
169 Harrison Bloom HBLOOM 011.44.1343.829268 23-3月 -98
SA_REP 10000 .2 148 80

170 Tayler Fox TFOX 011.44.1343.729268 24-1月 -98
SA_REP 9600 .2 148 80

171 William Smith WSMITH 011.44.1343.629268 23-2月 -99
SA_REP 7400 .15 148 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
172 Elizabeth Bates EBATES 011.44.1343.529268 24-3月 -99
SA_REP 7300 .15 148 80

173 Sundita Kumar SKUMAR 011.44.1343.329268 21-4月 -00
SA_REP 6100 .1 148 80

174 Ellen Abel EABEL 011.44.1644.429267 11-5月 -96
SA_REP 11000 .3 149 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
175 Alyssa Hutton AHUTTON 011.44.1644.429266 19-3月 -97
SA_REP 8800 .25 149 80

176 Jonathon Taylor JTAYLOR 011.44.1644.429265 24-3月 -98
SA_REP 8600 .2 149 80

177 Jack Livingston JLIVINGS 011.44.1644.429264 23-4月 -98
SA_REP 8400 .2 149 80

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
178 Kimberely Grant KGRANT 011.44.1644.429263 24-5月 -99
SA_REP 7000 .15 149

179 Charles Johnson CJOHNSON 011.44.1644.429262 04-1月 -00
SA_REP 6200 .1 149 80

180 Winston Taylor WTAYLOR 650.507.9876 24-1月 -98
SH_CLERK 3200 120 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
181 Jean Fleaur JFLEAUR 650.507.9877 23-2月 -98
SH_CLERK 3100 120 50

182 Martha Sullivan MSULLIVA 650.507.9878 21-6月 -99
SH_CLERK 2500 120 50

183 Girard Geoni GGEONI 650.507.9879 03-2月 -00
SH_CLERK 2800 120 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
184 Nandita Sarchand NSARCHAN 650.509.1876 27-1月 -96
SH_CLERK 4200 121 50

185 Alexis Bull ABULL 650.509.2876 20-2月 -97
SH_CLERK 4100 121 50

186 Julia Dellinger JDELLING 650.509.3876 24-6月 -98
SH_CLERK 3400 121 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
187 Anthony Cabrio ACABRIO 650.509.4876 07-2月 -99
SH_CLERK 3000 121 50

188 Kelly Chung KCHUNG 650.505.1876 14-6月 -97
SH_CLERK 3800 122 50

189 Jennifer Dilly JDILLY 650.505.2876 13-8月 -97
SH_CLERK 3600 122 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
190 Timothy Gates TGATES 650.505.3876 11-7月 -98
SH_CLERK 2900 122 50

191 Randall Perkins RPERKINS 650.505.4876 19-12月-99
SH_CLERK 2500 122 50

192 Sarah Bell SBELL 650.501.1876 04-2月 -96
SH_CLERK 4000 123 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
193 Britney Everett BEVERETT 650.501.2876 03-3月 -97
SH_CLERK 3900 123 50

194 Samuel McCain SMCCAIN 650.501.3876 01-7月 -98
SH_CLERK 3200 123 50

195 Vance Jones VJONES 650.501.4876 17-3月 -99
SH_CLERK 2800 123 50

EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE
----------- -------------------- ------------------------- ------------------------- -------------------- --------------
JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
---------- ---------- -------------- ---------- -------------
196 Alana Walsh AWALSH 650.507.9811 24-4月 -98
SH_CLERK 3100 124 50

197 Kevin Feeney KFEENEY 650.507.9822 23-5月 -98
SH_CLERK 3000 124 50

已选择107行。

SQL> host cls

SQL> select count(*) from hremp;

COUNT(*)
----------
107

已选择 1 行。

SQL> spool off

oracle第二天

标签:

原文地址:http://www.cnblogs.com/zszitman/p/5631602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!