【赛迪网-it技术报道】本文的主要内容包括:在oracle中实现自增型id,删除数据表中的重复记录。
一.自增型id
1.首先创建 sequence
create sequence seqmax increment by 1
2.得到一个id
select seqmax.nextval id from dual
3.若要删除一个sequence
drop sequence seqmax;
二.删除数据表中的重复记录
1.先创建一个表
create table "apptest" (
"id" integer primary key not null,
"mobile" nvarchar2(50) not null
);
2.假设其中手机号大量重复,要删除重复记录,可以有如下两种方法:
(1)简单利用rowid删除
delete from apptest a where rowid not in (select max(rowid) from apptest b where a.mobile=b.mobile);
据说,这种方法在数据量很大时,效率并不高
(2)利用分析函数
delete apptest where rowid in (
select rid from
(select rowid rid,row_number() over(partition by mobile order by id desc) rn from apptest )
where rn > 1) ;
(3)做temp表
闽公网安备 35060202000074号