Solved

Conditional data-transfer of a large table from one machine to another using Oracle

Posted on 2008-10-25
5
450 Views
Last Modified: 2013-12-18
A large table with over two million records has to be conditionally transferred from one Oracle user to another Oracle user in different machines.  We have to filter only the records created after a specified date, with another field beginning with a particular string, and with another field greater than a particular number.  The specified date, string and number are parameters, so can vary, and are not yet known.  It's a one-shot transfer, so this technique will be applied only one time.

Please describe your solution in two cases:

a) You can create a DBLink;
b) You aren't allowed to create a DBLink.
0
Comment
Question by:hc2342uhxx3vw36x96hq
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:hc2342uhxx3vw36x96hq
ID: 22807241
UP
0
 
LVL 10

Expert Comment

by:dbmullen
ID: 22810134
assuming the table doesn't have a LOB, fastest way to move the data is to just insert it over a link.

what is the SIZE of the table?
select bytes from dba_segments where owner = 'xxx' and segment_name = 'yyyyy';

now..  some are going to tell you to use export/import or data pump or pl/sql procedure with cursor or "oracle copy"
all of those will work fine..  but, for 2 million rows one time..  just insert the rows over the link.

with db_link
connect to target database
CREATE DATABASE LINK source_link CONNECT TO source_user IDENTIFIED BY 'pass'  USING 'SOURCE'; 
insert into target_table select * from source_table@source_link where......
;
commit;
 
without db_link
assume username/password are same on target/source
connect to target database
insert into owner.target_table select * from owner.source_table@source where......
;
commit;

Open in new window

0
 
LVL 1

Author Comment

by:hc2342uhxx3vw36x96hq
ID: 22815500
The size is the following: 190000000

(I've approximated the value, of course).

The table contains about 2 million records: with the where condition, they will become 1,75 million records.

With a simple insert statement you cannot do it.  With a cursor is it possible?

declare cursor cxxx is select * from source_table@source_link where date_field >= to_date (.....)

Is theren't a fastest way to copy?
0
 
LVL 10

Accepted Solution

by:
dbmullen earned 500 total points
ID: 22815577
190mb is pretty small...
With a simple insert statement you cannot do it.  
why not?  is there a CLOB/LOB/BLOG or something
the fastest way to move the data is to just INSERT it over a link..  try the "oracle copy command"  only thing about COPY, you have to put the select on ONE line so use the "_" if want to make it look pretty.
 

connect username/password@target_db
set arraysize 100
set copycommit 50
set long 4000
truncate table target_table;
COPY FROM username/password@source_db _
       TO username/password@target_db _
       insert target_table _
       USING  _
       SELECT * _
       FROM source_table _
       where.... _
       ;

Open in new window

0
 
LVL 1

Author Closing Comment

by:hc2342uhxx3vw36x96hq
ID: 31509915
OK, thanks!
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

Suggested Solutions

Title # Comments Views Activity
migration MS SQL database to Oracle 30 68
pivot rows to columns 1 34
Fill Date time Field 12 23
setting local variables in a cursor block 3 18
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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 copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

860 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