How to partition a non-partitioned table
You can partition a non-partitioned table three different ways:
A) export/import method
B) Insert with a subquery method
C) Partition exchange method
Either of these 3 methods will create a partitioned table from an existing
non-partitioned table.
A) export/import method
B) Insert with a subquery method
C) Partition exchange method
Either of these 3 methods will create a partitioned table from an existing
non-partitioned table.
A. Export/import method
--------------------
1) Export your table:
exp usr/pswd tables=numbers file=exp.dmp
2) Drop the table:
drop table numbers;
3) Recreate the table with partitions:
create table numbers (qty number(3), name varchar2(15))
partition by range (qty)
(partition p1 values less than (501),
partition p2 values less than (maxvalue));
4) Import the table with ignore=y:
imp usr/pswd file=exp.dmp ignore=y
The ignore=y causes the import to skip the table creation and
continues to load all rows.
B. Insert with a subquery method
-----------------------------
1) Create a partitioned table:
create table partbl (qty number(3), name varchar2(15))
partition by range (qty)
(partition p1 values less than (501),
partition p2 values less than (maxvalue));
2) Insert into the partitioned table with a subquery from the
non-partitioned table:
insert into partbl (qty, name)
select * from origtbl;
3) If you want the partitioned table to have the same name as the
original table, then drop the original table and rename the
new table:
drop table origtbl;
alter table partbl rename to origtbl;
C. Partition Exchange method
-------------------------
ALTER TABLE EXCHANGE PARTITION can be used to convert a partition (or
subpartition) into a non-partitioned table and a non-partitioned table into a
partition (or subpartition) of a partitioned table by exchanging their data
and index segments.
1) Create table dummy_t as select with the required partitions
2) Alter table EXCHANGE partition
with
Example
-------
SQL> CREATE TABLE p_emp
2 (sal NUMBER(7,2))
3 PARTITION BY RANGE(sal)
4 (partition emp_p1 VALUES LESS THAN (2000),
5 partition emp_p2 VALUES LESS THAN (4000));
Table created.
SQL> SELECT * FROM emp;
EMPNO ENAME JOB MGR HIREDATE SAL
--------- ---------- --------- --------- --------- ---------
7369 SMITH CLERK 7902 17-DEC-80 800
7499 ALLEN SALESMAN 7698 20-FEB-81 1600
7521 WARD SALESMAN 7698 22-FEB-81 1250
7566 JONES MANAGER 7839 02-APR-81 2975
7654 MARTIN SALESMAN 7698 28-SEP-81 1250
7698 BLAKE MANAGER 7839 01-MAY-81 2850
7782 CLARK MANAGER 7839 09-JUN-81 2450
7788 SCOTT ANALYST 7566 19-APR-87 3000
7839 KING PRESIDENT 17-NOV-81 5000
7844 TURNER SALESMAN 7698 08-SEP-81 1500
7876 ADAMS CLERK 7788 23-MAY-87 1100
7900 JAMES CLERK 7698 03-DEC-81 950
7902 FORD ANALYST 7566 03-DEC-81 3000
7934 MILLER CLERK 7782 23-JAN-82 1300
14 rows selected.
SQL> CREATE TABLE dummy_y as SELECT sal
FROM emp WHERE sal<2000;
Table created.
SQL> CREATE TABLE dummy_z as SELECT sal FROM emp WHERE sal
BETWEEN 2000 AND 3999;
Table created.
SQL> alter table p_emp exchange partition emp_p1
with table dummy_y;
Table altered.
SQL> alter table p_emp exchange partition emp_p2
with table dummy_z;
Table altered.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/38542/viewspace-926684/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- partition table and partition indexIndex
- 拆分Table 為Partition Table
- partition table test
- partition table(1)
- partition table(2)
- When to Partition a Table
- [Oracle] Partition table exchange Heap tableOracle
- Oracle 普通table 轉換為partition tableOracle
- create a partition table using a exsit table
- 分割槽表PARTITION table
- partition table update partition-key result in changing tablespace
- db2 partition table testDB2
- Interval Partition table 11G
- Oracle分割槽表(Partition Table)Oracle
- 分割槽表PARTITION table(轉)
- partition table中truncate應用
- How To Efficiently Drop A Table With Many Extents
- How to monitor data transaction on one table
- mysql partition table use to_days bugMySql
- 關於partition table import的問題Import
- doesn't contain a valid partition tableAI
- add hash partition , default tablespace for patitioned table
- How to Add a New Disk new partition in centos7CentOS
- [doc]How To Efficiently Drop A Table With Many Extents
- 【DB】Direct Path EXP Corrupts The Dump If An Empty Table Partition Exists
- Applying “Incremental Statistic” for Oracle Big Partition TableAPPREMOracle
- Data Warehouse Guide閱讀筆記(七):partition tableGUIIDE筆記
- How to Quickly Create a Copy of a Table using Transact-SQLUISQL
- How To Know If An Object (Table / Procedure / View /…) Is Currently BeingObjectView
- ext4 lvreduce報錯superblock or the partition table is likely to be corruptVRBloC
- TiDB 原始碼閱讀系列文章(二十)Table PartitionTiDB原始碼
- 今天測試了一下update partition table的part key
- ESP32 編譯報錯 57) boot: no bootable app partitions in the partition table編譯bootAPP
- best practice of rebuild your partition table local index online by using: "update indexes"RebuildIndex
- PARTITION partition01
- PARTITION partition02
- PARTITION partition04
- HOW TO SHRINK A TABLE USING ONLINE REDEFINITION (文件 ID 1357878.1)