SQL 如何从 Oracle 中的另一个数据库中创建一个表作为选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1207803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I create a table as a select from another database in Oracle?
提问by chris
Is it possible to create a table (in my dev db) using a SELECT from a different database?
是否可以使用来自不同数据库的 SELECT 创建表(在我的开发数据库中)?
I want something like:
我想要这样的东西:
create tmp_table as select * from prod_db.prod_schema.table
Is there syntax to do this, or do I need to create a database link first?
有没有语法可以做到这一点,还是我需要先创建一个数据库链接?
回答by Steve Schnepp
You have to create a datalink first.
您必须先创建一个数据链路。
Oracle cannot query other databases unless a DB link is created. If a DB link exists, as you remarked, you have to do :
除非创建数据库链接,否则 Oracle 无法查询其他数据库。如果存在数据库链接,如您所说,您必须执行以下操作:
create tmp_table as select * from prod_schema.table@prod_db
回答by chris
@Steve is correct that there has to be a DB Link, but the syntax is:
@Steve 是正确的,必须有一个数据库链接,但语法是:
create tmp_table as select * from table@dblink
回答by Mark Harrison
Don't forget to create your indexes. You can get this for all the tables in your schema with a query like this:
不要忘记创建索引。您可以使用如下查询为架构中的所有表获取此信息:
SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name)
FROM USER_INDEXES u;
回答by Ameya Save
CREATE TABLE table_name
AS SELECT * FROM schema_name.table_name;