本文共 870 字,大约阅读时间需要 2 分钟。
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)
原文地址
转载地址:http://iydzm.baihongyu.com/