in reply to need to look for data differences in same table in two database instances
#!/usr/bin/perl -w use strict; use DBI; use DBD::Oracle; my $db1 = DBI->connect("dbi:Oracle:server=XXXX;database=XXXX", "USER", +"PASSWD") or die "Failed to connect to the database!"; my $db2 = DBI->connect("dbi:Oracle:server=XXXX;database=XXXX", "USER", +"PASSWD") or die "Failed to connect to the database!"; my $table = "DUMMY"; # name of the table my $unique_id = "ID"; # unique id to identify the row my $sth1 = $db1->prepare( "select * from $table" ); my $sth2 = $db2->prepare( "select * from $table where $unique_id=?" ); $sth1->execute(); while (my $row = $sth1->fetchrow_hashref()) { my $found = 0; $sth2->execute( $row->{$unique_id} ); while (my $row2 = $sth2->fetchrow_hashref()) { # compare the row foreach (keys %$row) { if ($row{$_} ne $row2{$_}) { print "DIFF: (ID) $_\n"; break; } } } } $sth->finish; $dbh->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: need to look for data differences in same table in two database instances
by Anonymous Monk on Jan 09, 2004 at 17:03 UTC | |
by Anonymous Monk on Jan 09, 2004 at 20:44 UTC | |
by Roger (Parson) on Jan 10, 2004 at 00:58 UTC |