|
||||||||
| Navigate at FreeMegaZone Home Articles Tools Jobs Games Support Submit Content Advertise | ||||||||
Identifying and Removing Duplicate Data by using EXCEPTIONS INTO clause: In this case we will first create EXCEPTIONS table by using Oracle script utlexcpt.sql in the $ORACLE_HOME/RDBMS/ADMIN DIRECTORY. We will use the EXCEPTIONS INTO clause of the alter table command. Duplicate rows in your table will have their rows inserted into EXCEPTIONS table, even though the constraint addition fails. ALTER TABLE <TABLE_NAME> ADD CONSTRAINT MY_I UNIQUE (COL_NO) EXCEPTIONS INTO exceptions; Then we will find the duplicate rows by joining the table to the exception table. SELECT T1.COL_NO, T1.COL1 FROM <TABLE_NAME> T1, EXCEPTIONS E1 WHERE T1.ROWID = E1.ROW_ID; Finally we will delete rows from the table. DELETE FROM <TABLE_NAME> WHERE (COL_NO , ROWID) IN Enforcing Unique Constraint for New or Modified Records: You can enforce uniqueness for new or modified records in Oracle table containing duplicate data by creating a unique constraint with DEFERRABLE and NOVALIDATE keywords. First we will create table and insert some records into it including duplicate data. CREATE TABLE <TABLE_NAME> ( By default, constraints are created as NON DEFERRABLE and VALIDATE. Now we will create a unique constraint with DEFERRABLE and NOVALIDATE keywords. But you should specify the constarint as INITIALLY DEFERRED DEFERRABLE or DEFERRABLE INITIALLY IMMEDIATE. ALTER TABLE <TABLE_NAME> ADD CONSTRAINT MY_I UNIQUE (COL1) DEFERRABLE INITIALLY IMMEDIATE NOVALIDATE; You can use below command to verify the status from dictionary table. SELECT CONSTRAINT_TYPE, STATUS, DEFERRABLE, DEFERRED, VALIDATED FROM USER_CONSTRAINTS WHERE TABLE_NAME =<TABLE_NAME>; Now we will enable our constraint to NOVALIDATE. ALTER TABLE <TABLE_NAME> MODIFY CONSTRAINT MY_I ENABLE NOVALIDATE; The existing duplicate records remain there but now if you attempt to insert any further duplicate records then you will get an error. INSERT INTO <TABLE_NAME> VALUES (1); Oracle Delete (Remove) Duplicate Entries Software 7.0: Oracle Delete (Remove) Duplicate Entries Software 7.0 is great software by Sobolsoft that can help you search and delete duplicate data such as values, records, rows and numbers in your Oracle tables. This software gives you the ability to specify which fields you want to be used as criteria. Only one unique entry is left and all other redundant entries are removed. Click here to download Oracle Delete (Remove) Duplicate Entries Software 7.0
More Oracle Articles, Database Articles and DBA Tips
|
|
|||||||
| HOME ABOUT US SUPPORT SITE MAP PRIVACY POLICY TERMS OF USE SUBMIT CONTENT ADVERTISE | ||||||||
|
Copyright © 2007 - 2010 Oriole Intellect Inc. All rights reserved.
The name Oracle is a trademark of Oracle Corporation. Any other names used on this website may be trademarks of their respective owners |