Solved

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

Posted on 2011-02-21
4
1,437 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 73

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 73

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.

Join & Write a Comment

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now