Solved

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

Posted on 2011-02-21
4
1,445 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 500 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 76

Expert Comment

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

The docs have the syntax.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

790 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