1-- backup scott
exp
2-- create user
create user liuchao identified by liuchao default tablespace users quota 10M on users
grant create session, create table , create view to liuchao
3-- import the data
imp
insert into dept value values(50,'game','bj');
select * from dept;
//回滚
rollback;
//备份表(新建表并拷贝另一张表内容)
create table emp2 as select * from emp;
create table dept2 as select * from dept;
create table salgrade2 as select * from salgrade;
//查看数据库中表
select * from tab where tabtype='TABLE';
insert的三种方式
insert into dept2 valuse(50,'game','bj');
insert into dept2(deptno, dname) values(60,'game2');
insert into dept2 select * from dept;
rownum
select * from tab;
查询结果中有个伪字段 rownum
rownum 使用用一定的限制;
只能< 和<=配合使用;
select rownum r, ename from emp;
构造虚表能方便使用rownum;
select ename from (select rownum r, ename from emp) where r>10;
查询薪水最高的前五个员工;
下面的sql有误:
select ename, sal from emp where rownum <=5 order by sal desc;
错误的原因:他不是先排序再取前五行;
可以用子查询构造虚表;
select ename, sal from
( select ename, sal from emp order by sal desc) where rownum<=5;
查询薪水最高的6~9名的雇员;
select ename, sal from
(
select ename,sal,rownum r from
(
select ename,sal from emp order by sal desc
)
)
where r>=6 and r<=9