日期:2014-05-16  浏览次数:20850 次

求一条SQL语句删除重复记录
有一个表MyTable有两列A,B. 没有主键。因为没有主键,所以表中有重复的记录。

求一条SQL语句,删除重复的记录,相同的记录只保留一条。谢谢!
------解决方案--------------------
引用:
Quote: 引用:

如果你的表中,只有A、B两个字段那就没法用一条语句删除了,只能先用 insert into T_B select distinct * from MyTable ;然后再把原表全删了


能不能使用一个存储过程,先select distinct * from MyTable存到内存中,再把原表全部删了,再把内存中的记录插入到表中。存储过程应该怎么写,求指导。
行倒是行 但是一般不建议这么干
create or replace procedure pro_lwb_dd as
cursor c_find is select distinct* from t;
cc c_find%rowtype;
begin
  open c_find;
  delete from t;
  loop
     fetch c_find into cc;
          exit when c_find%notfound;
          insert into t values(cc.字段1,cc.字段2);
    end loop;
    commit;
  close c_find;
end;