Reputation: 7940
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?
Upvotes: 0
Views: 5526
Reputation: 4432
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
Upvotes: 4