[英]Oracle 12c - how to create a new table form existing table with all data, partitions and indexes like in first table?
Table t1 is partitioned and has data. 表t1已分区并具有数据。
I am using this command to transfer data from t1 to t2: 我正在使用以下命令将数据从t1传输到t2:
CREATE TABLE t2
TABLESPACE ts1
AS
select * from t1;
However this copies all the data but does not create partitions as in t1. 但是,这会复制所有数据,但不会像t1一样创建分区。 Is there a command to copy all the data plus partitions and indexes from t1 to t2? 是否有命令将所有数据以及分区和索引从t1复制到t2?
Use dbms_metadata
to get the whole structure. 使用dbms_metadata
获取整个结构。
SELECT dbms_metadata.get_ddl( 'TABLE', 'SOURCE_TABLE_NAME' ) FROM DUAL;
Run the DDL
generated from this query replacing the table name with new table name. 运行从该查询生成的DDL
,用新的表名替换表名。
If your source_table is in a different schema, then 如果您的source_table在其他架构中,则
SELECT dbms_metadata.get_ddl( 'TABLE', 'SOURCE_TABLE_NAME', 'SOURCE_SCHEMA_NAME' ) FROM DUAL;
It's not possible in the same schema - it will fail with an object already exists error. 在同一模式下不可能-它将因对象已存在错误而失败。 If it is a different schema, then try this: export and import by renaming the table while importing to another schema. 如果它是不同的架构,请尝试以下操作:在导入到另一个架构时,通过重命名表来进行导出和导入。
Otherwise try with DBMS_METADATA.GET_DDL. 否则,请尝试使用DBMS_METADATA.GET_DDL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.