Remove Duplicate Rows from Oracle Database Table

If you need to remove duplicate rows from an Oracle Database Table, you can use different approaches. For example, you can use the DELETE command with a criteria that selects only duplicates. Usually it is faster to create a new table with distinct rows and replace the old table with the new one.

-- Create a new table with distinct row values.

CREATE TABLE temp_table_name AS

   SELECT DISTINCT * 

      FROM source_table_name;

 

-- Replace the original table with the new table.

DROP TABLE source_table_name;

RENAME temp_table_name TO source_table_name;

Of course in real life the are always complications. For example, the above example doesn’t take in account constraints and indexes. You should carefully investigate all dependencies to avoid performance degradation and to preserve data integrity.

你可能感兴趣的:(database)