Thank you both. I'm glad that it's not too bad.
What this does is creates a hash of tables for a db schema with the number of rows.
DB1 Table1 = 4500 rows Table2 = 500 rows DB2 Table1 = 4502 rows Table2 = 500 rows Table3 = 1000 rows


and then compare the two result sets to detirmine extraneous tables or difference in rowcounts. I will post an update of my code after a little work.

UPDATE

#!/usr/local/bin/perl -w use strict; use DBI; use Env; my @DB = ('DB1','DB2'); my $user = "user"; my $passwd = "passwd"; my $schema = "USER"; my $DBHome = "/U01/oracle/ora817"; $ENV{"ORACLE_HOME"} = $DBHome; my %dbs; &query_databases(); my $result = do_compare(); sub query_databases { for (@DB) { my ($dbh,$sth,@TABLE_NAMES,$TABLE_NAME,$rowcount,%result); my $db = $_; # Login to the database $dbh = DBI->connect("dbi:Oracle:$db",$user,$passwd,{AutoCommit => +0, RaiseError => 1}) || die("Oracle login FAILED, $DBI::errstr"); $sth = $dbh->prepare("select TABLE_NAME from dba_tables where owne +r=?"); $sth->execute( $schema ) || die $dbh->errstr; while ( $TABLE_NAME = $sth->fetchrow_array ) { push(@TABLE_NAMES,$TABLE_NAME); } die $sth->errstr if $sth->err; for $TABLE_NAME ( @TABLE_NAMES ) { $sth = $dbh->prepare("select count(*) from $schema.$TABLE_NAME" +); $sth->execute || die $dbh->errstr; while ($rowcount = $sth->fetchrow_array ) { $dbs{$db}->{$TABLE_NAME} = $rowcount; } } $dbh->disconnect; } } sub do_compare { for my $key ( keys %dbs ) { print "Database is $key\n"; for my $key2 ( sort keys %{$dbs{$key}} ) { print "$key2\t $dbs{$key}->{$key2}\n"; } } }


Well, I'm no expert and had some troubles referencing the %dbs hash, so I made it "global" and this will print out everything.
However, now I need to compare the two hashes and report tables that only exist in one hash, then compare rows if they exist in both. It's late in the day and I'm coming up blank on where to even start. :(

In reply to Re: Re: References and passing data to a different sub. by bcole23
in thread References and passing data to a different sub. by bcole23

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.