Skip to Main Content
  • Questions
  • copy data from one instance to another

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ervin.

Asked: February 01, 2007 - 4:23 pm UTC

Last updated: February 05, 2007 - 6:31 pm UTC

Version: 9i, 10g

Viewed 1000+ times

You Asked

Hi Tom, I have a problem trying to copy data from one instance to another instance using db link. i have a set of kornsheel scripts. table names are put into a file. my kornshell script will read the file and spawn four processeses at a time. so that means that 4 processes in parallel will copy data and table name is read from the file.

i am passing two parameters to my shell script. pdate and loc_id. as mentioned above, the table names are store in a file. not all tables have pdate and loc_id as a column. some tables in the list have both columns, some have only one column(pdate) and some don't have either ptime or loc_id. i am using insert /*+append*/ to insert into data into the table.

since not all the tables have both columns (pdate and loc_id) i cannot say something like
insert /*+append*/ into table_name
select * from table_name where bdate = p_date and b_loc_id = loc_id

how can i write an insert statement that takes care of all my scenarios described above?

for example, for tables with both columns i would like to do this
insert /*+append*/ into table_name
select * from table_name where bdate = p_date and b_loc_id = loc_id

for tables with pdate, i would like to do this
insert /*+append*/ into table_name
select * from table_name where bdate = p_date

and for tables with none of those columns i would like this
insert /*+append*/ into table_name
select * from table_name

please help. if my approach is not correct, i will appreciate if you can share your ideas. many thanks

and Tom said...

Personally, I would not be using shell scripts for this - no error handling, and such.

I would be using static sql in plsql stored procedures.
I would use dbms_job to submit all of them.
And set job_queue_processes to control the degree of concurrency.

You need a bit of procedural code to notify you of errors, You might need a bit to massage the data. Using ksh and sqlplus isn't very "robust". Could you do it? sure, but it would be soooo much easier and especially easier to maintain if you created a single plsql package with all of your copy procedures and just let the database do the work using static sql.

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

DBMS Jobs Vs Scripts

Hariharan R, February 05, 2007 - 10:49 am UTC

Hi Tom, That Suggestion you have given at many a place to use DBMS Jobs rather than Shell scripts and Sqlplus. But when I speak with many of database administrators, they feel the scripts have greater control than the DBMS Jobs. Can you give us some strong advantage of the DBMS Jobs rather than any shell scripts.

Tom Kyte
February 05, 2007 - 11:15 am UTC

scripts have no control - what are they talking about?

what sort of ability do you have to do complex error handling?
who is responsible to restart them when they fail?


sample code

Ervin Rodriguez, February 05, 2007 - 3:49 pm UTC

thanks Tom, it was very helpful. as i mentioned above, some tables contain bdate and loc_id column, some tables only bdate and some don't have either bdate or loc_id. how can i write an insert statement that will take care of all 3 scenerios describe above.

for example, for tables with both columns i would like to do this
insert /*+append*/ into table_name
select * from table_name where bdate = p_date and b_loc_id = loc_id

for tables with pdate and no loc_id, i would like to do this
insert /*+append*/ into table_name
select * from table_name where bdate = p_date

and for tables with none of those columns (bdate and loc_id) i would like this
insert /*+append*/ into table_name
select * from table_name
Tom Kyte
February 05, 2007 - 6:31 pm UTC

use STATIC SQL!!!!!!!

that is what I wrote.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library