简体   繁体   English

从现有分区表创建分区表

[英]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: 我有一个现有的分区表[称之为A],我想使用以下命令创建第二个表B:

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. A是一个分区表,我也希望B是一个分区表,但是上面的命令创建了一个普通表。

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(). 您将需要为表B指定分区子句。您可以使用dbms_metadata()获得DDL。

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 然后只需在CREATE TABLE语句中更改表名

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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