Method 3 for deleting duplicate records in an Oracle database

Source: Internet
Author: User

Introduction: Oracle DatabaseDuring operations, there will inevitably be many repeated records. These repeated records are useless data, so you can safely delete them. For a long time, we will introduce some common methods for deleting Repeated Records in Oracle database tables.

Method 1:

Delete from tb_channel a where a. rowid in

(Select max (B. rowid) from tb_channle B

Where a. policyno = B. policyno and a. classcode = B. classcode );

-- This method is generally slow when the data record exceeds 0.1 million.

Method 2:

-- Create a temporary table, -- clear the original table, -- insert it back to the original table, as shown in the following example:

Create table temp_emp as (select distinct * from employee );

Truncate table employee;

Insert into employee select * from temp_emp;

-- This method applies to large tables. Because it is a block operation, it is much more efficient for large tables.

Method 3:

-- Create a new table, -- repeat the table, and -- delete the original table, as shown in the following example:

Select distinct * into new_table from old_table

Order by primary key

Drop table old_table

Exec sp_rename new_table, old_table;

-- This method applies to large tables. Because it is a block operation, it is much more efficient for large tables.

In the preceding three methods, the number of tables is different. Therefore, you can flexibly use the table based on the actual situation. No matter which one you use, you can use it conveniently and quickly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.