create table emps1 as select * from emps; //备份一个emps表,创建一个和emps一样的表emps1
insert into emps(属性) values(属性值);//在表emps中插入一条新的内容,注意: 在添加不完整信息的时候,所添加的属性必须有约束性的属性
delete from emps where empno=7936;//删除表emps中empno=7936的那一条信息
update emps set ename='malin' where empno=7937;//更新empno=7937的ename,将ename改为malin
集合类型
select * from emp where sal between 800 and 1300
intersect
select * from emp where sal between 1200 and 1400;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ----- ----- ------
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10
//显示表emp中同时满足两个条件的员工信息,即显示表emp中sal在1200~1300之间的员工信息
select * from emp where sal between 800 and 1300
union
select * from emp where sal between 1200 and 1400
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------- ---------- --------- ---------- -------------- ----- ----- ------
7369 SMITH CLERK 7902 17-12月-80 800 20
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7876 ADAMS CLERK 7788 12-1月 -83 1100 20
7900 JAMES CLERK 7698 03-12月-81 950 30
7934 MILLER CLERK 7782 23-1月 -82 1300 10
select * from emp where sal between 800 and 1300
union all
select * from emp where sal between 1200 and 1400
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
--------- ---------- --------- ---------- -------------- ----- ----- ------
7369 SMITH CLERK 7902 17-12月-80 800 20
7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
7876 ADAMS CLERK 7788 12-1月 -83 1100 20
7900 JAMES CLERK 7698 03-12月-81 950 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
7934 MILLER CLERK 7782 23-1月 -82 1300 10
//union 显示的是符合条件但是不包括重复信息 union all 查询符合两个条件的信息,会显示重复信息注意:会有重复信息,因为两个条件中有相同的小条件
select * from emp where sal between 800 and 1300
minus
select * from emp where sal between 1200 and 1400
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------- ---------- --------- ---------- -------------- ----- ----- ------
7369 SMITH CLERK 7902 17-12月-80 800 20
7876 ADAMS CLERK 7788 12-1月 -83 1100 20
7900 JAMES CLERK 7698 03-12月-81 950 30
//显示的是符合前面条件且不符合后面条件的信息
Oracle分页查询
SQL> select rownum,e.* from emp e where rownum<=3;
ROWNUM EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
---------- ---------- ---------- --------- ---------- -------------- ----- -----
------
1 7369 SMITH CLERK 7902 17-12月-80 800
20
2 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300
30
3 7521 WARD SALESMAN 7698 22-2月 -81 1250 500
30
SQL> select * from (select rownum as r,e.* from emp e) el where el.r>3 and el.r<
=6;
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- ---------- --------- ---------- -------------- ----- ----- ------
4 7566 JONES MANAGER 7839 02-4月 -81 2975 20
5 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
6 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
//这是没有排序的分页,按表中内容直接分页
SQL> select * from (select rownum as r,e.* from (select * from emp order by sal
desc) e) el where el.r>0 and el.r<=3;
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- ---------- --------- ---------- -------------- ----- ----- ------
1 7839 KING PRESIDENT 17-11月-81 5000 10
2 7902 FORD ANALYST 7566 03-12月-81 3000 20
3 7788 SCOTT ANALYST 7566 09-12月-82 3000 20
SQL> select * from (select rownum as r,e.* from (select * from emp order by sal
desc) e) el where el.r>3 and el.r<=6;
R EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- ---------- --------- ---------- -------------- ----- ----- ------
4 7566 JONES MANAGER 7839 02-4月 -81 2975 20
5 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30
6 7782 CLARK MANAGER 7839 09-6月 -81 2450 10
//有排序的分页,以工资的多少为例