要刪除Oracle表中的重復行,可以使用以下方法之一:
WITH CTE AS (
SELECT
column1,
column2,
ROW_NUMBER() OVER (PARTITION BY column1, column2 ORDER BY column1) AS rn
FROM your_table
)
DELETE FROM your_table
WHERE (column1, column2) IN (SELECT column1, column2 FROM CTE WHERE rn > 1);
DELETE FROM your_table a
WHERE EXISTS (
SELECT 1
FROM your_table b
WHERE a.column1 = b.column1
AND a.column2 = b.column2
AND a.rowid > b.rowid
);
無論使用哪種方法,都需要謹慎操作,確保只刪除重復行而不是有用的數據。最好在刪除之前備份數據以防止意外情況。