Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle -- copy table from one db to another db ?

Posted on 2011-02-21
4
Medium Priority
?
1,460 Views
Last Modified: 2013-12-19
I have two databases (test & dev) on the same machine (server1) and tried running the below in Oracle SQL Developer, but get errors.

How can i easily copy the test database accounting_structure_tab table into dev ?

truncate DEV.ACCOUNTING_STRUCTURE_TAB
INSERT INTO DEV.ACCOUNTING_STRUCTURE_TAB
SELECT *
from TEST.ACCOUNTING_STRUCTURE_TAB
0
Comment
Question by:finance_teacher
  • 2
4 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 34944508
create a database link in DEV pointing to TEST


then....  (you need "truncate table"  not "truncate")

truncate table ACCOUNTING_STRUCTURE_TAB;



INSERT INTO ACCOUNTING_STRUCTURE_TAB
SELECT *
from ACCOUNTING_STRUCTURE_TAB@your_test_db_link;

I assume the table structure is the same in both dev and test?
0
 
LVL 18

Expert Comment

by:sventhan
ID: 34944519
Do you have a DBLInk? if you do not create one.

INSERT INTO DEV.ACCOUNTING_STRUCTURE_TAB
SELECT *
from TEST.ACCOUNTING_STRUCTURE_TAB@dblink
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 34944527
if you want to do this from within a pl/sql procedure or anonymous block,  you must wrap the truncate inside an execute immediate  because trucate is ddl which isn't part of pl/sql syntax


begin

execute immediate 'truncate table ACCOUNTING_STRUCTURE_TAB';

INSERT INTO ACCOUNTING_STRUCTURE_TAB
SELECT *
from ACCOUNTING_STRUCTURE_TAB@your_test_db_link;

end;
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34944846
There is also a sql COPY command.

The docs have the syntax.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question