Solved

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

Posted on 2008-10-25
5
447 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

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to recover a database from a user managed backup

803 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