Preparations for clearing historical Oracle Data

Source: Internet
Author: User

The customer requested that the historical data in the database of the two projects on the current network be cleaned up recently, so he sorted out the section usage in the next application, mainly to view the table section. The script used is as follows.

Create or replace procedure get_tab_rows
As
-- Drop Table tabsrow
-- Create Global Temporary Table tabsrow (Name Varchar2 (30), Rowsnum Number) On Commit Delete Rows;
-- Create Table tabsrow (Name Varchar2 (30), Rowsnum Number );
V_ SQL Varchar2 (300 );
Begin
Execute Immediate 'truncate table tabsrow ';
For x In (Select OWNER, table_name From dba_tables Where owner = 'xxx' and table_name <> 'test') Loop
V_ SQL: = 'insert into tabsrow Select ''' | x. table_name | ''', Count (1) from' | X. OWNER | '. '| x. table_name;
Execute Immediate V_ SQL;
End Loop;
Commit;
End;
/
Exec get_tab_rows;
Select a. Owner,
A. Table_Name,
-- B. Segment_Name,
A. Tablespace_Name,
B. Bytes/1024/1024 as "size (Mb)", e. rowsnum,
-- B. Blocks,
-- C. Table_Name,
C. Partitioning_Type,
D. column_name
From Dba_Tables
Left Join (Select B. Segment_Name, Sum (B. Bytes) Bytes, Sum (B. Blocks) Blocks
From Dba_Segments B
Where B. OWNER = 'xxx'
And B. segment_type NOT IN ('index ')
Group By B. Segment_Name) B on a. Table_Name = B. Segment_Name
Left Join Dba_Part_Tables c On a. Table_Name = c. Table_Name
Left join Dba_Part_Key_Columns d on d. owner = 'xxx'
And a. table_name = d. name
Left join tabsrow e on a. table_name = e. name
Where a. Owner = 'xxx' order by "size (Mb)" desc;
Drop procedure get_tab_rows;
Drop Table tabsrow;

-The End-


Gtlions @ CSDNStudy... Practice

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.