Hi, first post, and also new to Oracle, so double-scary...
I've inherited an Oracle database and on looking at one procedure I'm seeing SQL which is intended to remove duplicates from a table.
Effectively it:
- declares a CURSOR to find the duplicates, which selects four fields and a count(*), uses a HAVING COUNT(*) > 1 and a GROUP BY on the same four fields
- Loops the cursor, copying the first instance of each duplicate using "rownum < 2" into a temp table
- delete ALL duplicates in source table
- re-INSERT the uniques/originals back into source table from the temp table
To me (MS SQL experience) this looks quite inefficient: a quick google yields lots of single-statement methods of reducing duplicates down to unique records (e.g.
Delete duplicate rows from Oracle tables)
I guess my question to the Oracle community is, since I'm a beginner to Oracle, am I looking at a really inefficient bit of SQL, or did the developer before me know some secret performance reason why this "select, copy out, delete, copy back again" method was adopted?
Thanks,
Clumsy