Partition big data tables in Oracle databases to improve data reading efficiency

Source: Internet
Author: User

Large data tables in the Oracle database are partitioned to improve data reading efficiency:

In PLSQL, directly add the Code:

-- Purpose: to partition and convert large table data. In this example, only 5000 pieces of data are used;
-- Create Table T
Create table t (id number, name varchar2 (10 ));
Insert into t select rownum + 4, '1, 5000, 4' from dual connect by rownum <=;
Commit;
Select count (1) from t;

-- Create a tablespace
Create tablespace ts_1 datafile 'e: \ oracle \ product \ 10.2.0 \ oradata \ orcl \ ts_1.dbf' size 50 m reuse;
Create tablespace ts_2 datafile 'e: \ oracle \ product \ 10.2.0 \ oradata \ orcl \ ts_2.dbf' size 50 m reuse;
Create tablespace ts_3 datafile 'e: \ oracle \ product \ 10.2.0 \ oradata \ orcl \ ts_3.dbf' size 50 m reuse;
 
-- Create a new table and partition
Create table t_new partition by range (id )(
Partition p1 values less tha (2000) tablespace ts_1,
Partition p2 values less than (4000) tablespace ts_2,
Partition p3 values less than (maxvalue) tablespace ts_3)
As select * from t;
 
-- Delete the old table and change its name
Truncate table t;
Drop table t;
Alter table t_new rename to t;
 
-- Check the data of each partition
Select count (*) from t partition (p1 );
Select count (*) from t partition (p2 );
Select count (*) from t partition (p3 );

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.