Oracle Library Delete removes tens of thousands of common heap table data

Source: Internet
Author: User

Requirements: Oracle Database Delete Deletes the normal heap table thousands history.

Effects of direct deletion:

1. An issue that could result in a final deletion failure due to insufficient undo table space;

2. May cause the Undo table space to be overused, affecting the normal operation of other users.

Improvement Scenario: Every 1k row is deleted and submitted once. (so that a big thing is broken up into a number of small things)

Note: To remove all records before 2014 as an example, please modify them according to your actual situation to prevent accidental operation.

Method 1
Declare     cursor [Del_cursor]  is SelectA.*, A.rowid row_id from [table_name]AOrder  byA.rowid;begin      for V_cusor inch [Del_cursor]Loopif V_cusor. [Time_stamp] <To_date ('2014-01-01','YYYY-MM-DD') Then               Delete  from [table_name] whererowID= V_cusor. row_id; End if; ifMoD[Del_cursor]%RowCount, +)=0  Then               Commit; End if; EndLoop; Commit;End;

Description of variables in Method 1:

[del_cursor] CURSOR name [table_name] The table name of the data you want to delete [Time_stamp] the Time field name of the table you are using as the filter condition
Method 2
DeclareMaxRows Number default  +;d elete_ct Number default 0;beginSelect Count(1)/MaxRows intoDelete_ct from [table_name] where[Time_stamp]<to_date ('2014-01-01','yyyy-mm-dd '); forIinch 1.. TRUNC (DELETE_CT)+1LoopDelete [table_name] where[Time_stamp]< to_date ('2014-01-01','yyyy-mm-dd ')        andRowNum<=MaxRows;Commit;EndLoop;End;

Description of variables in Method 2:

[table_name] The table name of the data you want to delete [Time_stamp] the Time field name of the table you are using as the filter criteria
Note

The core of the two approaches is to split a big thing into a number of small things, regardless of which method, it is recommended to first Test in the corresponding test environment before considering whether it can be used in the actual production.

By the way, such a large table should be considered whether the composition of the table can be modified.

Oracle Library Delete removes tens of thousands of common heap table data

Related Article

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.