这种情况下游标是无法定位的,最好select distinct * into #tem from xxx 然后处理
select distinct * into #tem from xxx drop table xxx select * into xxx from #tem
先insert into #aaa select distinct * from 表名 where 条件 再delete from 表名 where 条件 再insert into 表名 select * from #aaa 大概就是这样
oracle下可以这么做: delete from table1 t1 where rowid=(select min(rowid) from table1 t2 where t2.field1=t1.filed1) and 你的条件 table1.field1是你可以确定有重复记录的条件字段,如果需要多个字段才能确定重复,就是t2.field1=t1.filed1 and t2.field2=t1.filed2 ... and t2.fieldn=t1.filedn
像下面这样即可DECLARE cur CURSOR FOR SELECT * FROM 表名 where 条件 OPEN cur FETCH NEXT FROM curDELETE FROM 表名 WHERE CURRENT OF curCLOSE cur DEALLOCATE cur
然后处理
drop table xxx
select * into xxx from #tem
再delete from 表名 where 条件
再insert into 表名 select * from #aaa
大概就是这样
delete from table1 t1 where rowid=(select min(rowid) from table1 t2 where t2.field1=t1.filed1) and 你的条件
table1.field1是你可以确定有重复记录的条件字段,如果需要多个字段才能确定重复,就是t2.field1=t1.filed1 and t2.field2=t1.filed2 ... and t2.fieldn=t1.filedn
FOR SELECT * FROM 表名 where 条件
OPEN cur
FETCH NEXT FROM curDELETE FROM 表名
WHERE CURRENT OF curCLOSE cur
DEALLOCATE cur