Oracle分页
方法一:select a.* from (select rownum rn ,ename from emp where rownum<=10 )a where a.rn>5
方法二:select * from ( select rownum rn ,ename from(select * from emp) where rownum <=10) where rn >5
方法三:select * from ( select rownum rn,ename from emp)a where a.rn between 6 and 10
Oracle去重
delete from emp a where a.rowid not in(select max(rowid) from emp r where a.ename=r.ename)
另外还要注意:
1, rownum不能以任何基表的名称作为前缀。
2,子查询中的rownum必须要有别名,否则还是不会查出记录来,这是因为rownum不是某个表的列,如果不起别名的话,无法知道rownum是子查询的列还是主查询的列
3,查询rownum在某区间的数据,那怎么办?从上可以看出rownum对小于某值的查询条件是认为为true的,rownum对于大于某值的查询条件直接认为是false的,但是可以间接的让它转为认为是true的。那就必须使用子查询。
4,rownum和排序。子查询。具体很多实现细节还需今后多加验证。
复制表(Oracle)
create table a as select * from b where 1=2 (只复制表结构,而不复制数据)
create table a as select * from b(复制表结构和数据)
insert into a select * from a (蠕虫复制)