Reputation: 37480
Is it possible to create a table (in my dev db) using a SELECT from a different database?
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?
Upvotes: 10
Views: 53239
Reputation: 33
If anyone is getting ORA-00901: invalid CREATE command
with @chris's answer, try adding TABLE
after CREATE
:
CREATE TABLE TEMP_TABLE AS SELECT * FROM TABLE@DB_LINK;
Upvotes: 0
Reputation: 11
CREATE TABLE table_name
AS SELECT * FROM schema_name.table_name;
Upvotes: -2
Reputation: 304662
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;
Upvotes: 1
Reputation: 4710
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 :
create tmp_table as select * from prod_schema.table@prod_db
Upvotes: 12
Reputation: 37480
@Steve is correct that there has to be a DB Link, but the syntax is:
create tmp_table as select * from table@dblink
Upvotes: 4