Oracle day05 索引_数据去重

索引
自动:当在表上定义一个primary key或者unique 约束条件时,oracle数据库自动创建一个对应的唯一索引.
手动:用户可以创建索引以加速查询
在一列或者多列上创建索引:
create index index on table (column[,column]...);

 

下面的索引将会提高对emp表基于ename字段的查询速度
create index emp_last_name_idx on emp(ename)

 

通过drop index 命令删掉一个索引
drop index index

 

删掉upper_last_name_idx索引
drop index upper_last_name_idx;

 

 
Top-N
语法:
select [column_list],rownum from (select [column_list] from table order by top-n_column) where rownum<=n;

 

rowid
rowid是oracle 实际存在的值,是唯一的值
rownum是一个虚拟的顺序值,前提是一定要排序
select emp.* ,rowid from emp;
 
delect from emp e where rowid not in(select min(rowid) from emp group by ename)

 

 

 
 
删除重复数据
如何只显示重复数据,或不显示重复数据
显示重复:
select * from tablename group byid having count(*)>1

 

不显示重复:
select * from tablename group byid having count(*)=1

 

删除重复数据原型:
delete from temp where rowid not in( select min(rowid) from emp group by ename having count(*)>=1)

 

 
posted @ 2019-04-21 15:42  ___mouM  阅读(501)  评论(1编辑  收藏  举报