简体   繁体   English

Oracle 12c-如何使用现有表(如第一个表)创建一个包含所有数据,分区和索引的新表?

[英]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.

相关问题 Oracle 12c - 如何查看某个表的所有分区和子分区以及每个表的记录数 - Oracle 12c - how to see all partitions and sub-partitions for some table and number of records for each Oracle 12c-如何对现有表进行分区? - Oracle 12c - how to partition existing table? Oracle 12c-对于具有分区和子分区的表,应使用哪个索引 - Oracle 12c - which index should be used for a table with partitions and sub-partitions Oracle 12c - 如何使用列表分区自动创建新分区 - Oracle 12c - how to create new partitions automatically with list partitions 更改表 SQL Oracle - 12c - ALTER TABLE SQL Oracle - 12c 如何在 Oracle 12c 中基于一个整数列(每个值 = 1 个分区)创建分区表? - How to create partitioned table based on one Integer column (each value = 1 partition) in Oracle 12c? Oracle 12C - JSON_TABLE - 当 json 列为 null 时如何返回表中的其他列 - Oracle 12C - JSON_TABLE - How to return other columns in the table when json column is null Oracle 12c-如何将另一个表的主键多次插入表中 - Oracle 12c - How to insert primary key of another table multiple times into a table Oracle 12c JSON TABLE解析错误处理 - Oracle 12c JSON TABLE parsing error handling 用户无法查看表条目oracle 12c - User not able to view table entries oracle 12c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM