timo has asked for the wisdom of the Perl Monks concerning the following question:

I need to compare the data in table between 2 databases. I've found an Oracle command that will do just that but I'm having difficulty implementing it in perl. Here is what I have so far:
my $sqlstr ="select table_name". " from Dba_tables". " where owner = '$schema'". " order by table_name"; my $sth=$db1->prepare($sqlstr) or print STDOUT "Query:GetDataF +ast Failed"; $sth->execute; my $table_names = $sth->fetchall_arrayref; $sth->finish; for $table_names_r (@{$table_names}) { my $sqlstr ="select column_name". " from Dba_tab_columns". " where owner = '$schema'". " and table_name = '$table_names_r->[0]'". " order by column_name"; my $sth=$db1->prepare($sqlstr) or print STDOUT "Query:GetD +ataFast Failed"; $sth->execute; my $column_names = $sth->fetchall_arrayref; $sth->finish; my $sqlstr2 ="select *". " from $schema.$table_names_r->[0]". + " MINUS". " select *". " from $schema.$table_names_r->[0]".'@'."$confi +g{database_2}"; print STDOUT "Table: $schema.$table_names_r->[0]"; my $sth2=$db1->prepare($sqlstr2) or print STDOUT "Query:Ge +tDataFast Failed"; $sth2->execute; my $results = $sth2->fetchall_arrayref; $sth2->finish;
$sqlstr2 holds the query in question. Is there another way to do this without first creating a dblink in one of the databases? I'd like to be able to do this on any set of databases without creating the dblink.

Replies are listed 'Best First'.
Re: How to Compare Data in 2 Separate Databases
by malloc (Pilgrim) on Nov 30, 2001 at 05:13 UTC
    AFAIK, you definitely need the dblink to be there already when accessing across databases in Oracle. But you can always just use two DataBase Handles, spool the data from both db's with the same query run on both $dbh's to two data structures in Perl, and compare those. Good Luck!

    -malloc
      The SQL commands JOIN or UNION may make this easier for you.
Re: How to Compare Data in 2 Separate Databases
by gmax (Abbot) on Dec 04, 2001 at 17:56 UTC
Re: How to Compare Data in 2 Separate Databases
by wileykt (Acolyte) on Nov 30, 2001 at 22:46 UTC
    By using minus you will only get the columns that are in the first table and not the second. If this is the result you're looking for, then I suggest using specific column names rather than *, unless you want all columns. If you want everything that exists in both tables, use union. If you're having trouble getting minus to work, look at the syntax in the sql reference here: sql ref for "where not exists".

    There is no way around using db links when accessing different databases.
    -kw