简体   繁体   中英

Create a partitioned table from existing partitioned table

I have an existing partitioned table [Lets call it A] and I want to create a second table B using following command:

Create table B as select * from A where 1=2;

A is a partitioned table and I also want B to be a partitioned table but the above command creates a normal table.

Is there a way by which I can clone a partitioned table?

You will need to specify the partitioning clause for table B. You can get the DDL using dbms_metadata().

set long 100000

select dbms_metadata.get_ddl( 'TABLE','EMP2' ) from dual

    DBMS_METADATA.GET_DDL('TABLE','EMP2')
    --------------------------------------------------------------------------------

  CREATE TABLE "SCOTT"."EMP2"
   (    "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
        "ENAME" VARCHAR2(10),
        "JOB" VARCHAR2(9),
        "MGR" NUMBER(4,0),
        "HIREDATE" DATE,
        "SAL" NUMBER(7,2),
        "COMM" NUMBER(7,2),
        "DEPTNO" NUMBER(2,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM"
  PARTITION BY RANGE ("EMPNO")
 (PARTITION "P1"  VALUES LESS THAN (7500) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM" ,
 PARTITION "P2"  VALUES LESS THAN (7600) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM" )

Then just change the table name in the CREATE TABLE statement

Syntax for creating one table from a another with partitioning...

 create table junk
 partition by hash(empno) partitions 2
 as
 select * from emp
 where 1=2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM