我有一个现有的分区表[让我们称之为A],我想使用以下命令创建第二个表B:
Create table B as select * from A where 1=2;
A是分区表,我也希望B是分区表,但上面的命令会创建一个普通表。
有没有办法克隆分区表?
答案 0 :(得分:2)
您需要为表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" )
然后只需更改CREATE TABLE语句中的表名
使用分区创建另一个表的语法...
create table junk
partition by hash(empno) partitions 2
as
select * from emp
where 1=2