oracle学习总结(二)
一.自增型ID
1.首先创建 sequence
create sequence seqmax increment by 1
2.得到一个ID
select seqmax.nextval ID from dual
3.若要删除一个sequence
drop sequence seqmax;
二.删除数据表中的重复记录create sequence seqmax increment by 1
2.得到一个ID
select seqmax.nextval ID from dual
3.若要删除一个sequence
drop sequence seqmax;
1.先创建一个表
2.假设其中手机号大量重复,要删除重复记录,可以有如下两种方法:
(1)简单利用rowid删除
据说,这种方法在数据量很大时,效率并不高
(2)利用分析函数
(3)做temp表
CREATE TABLE "APPTEST" (
"ID" INTEGER primary key NOT NULL,
"MOBILE" nvarchar2(50) NOT NULL
);
"ID" INTEGER primary key NOT NULL,
"MOBILE" nvarchar2(50) NOT NULL
);
(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) ;
select rid from
(select rowid rid,row_number() over(partition by mobile order by id desc) rn from APPTEST )
where rn > 1) ;