tags:

views:

119

answers:

2

I want to read a table in oracle which contains database links for checking availabilty of each database link and return only the bad results for each database link and error message.

I want to fetch this lookup table into an array, and pass the entries of db_link to a select from dualQdb_link, test all the entries of lookup to test for success or failure. This seems very hard to achieve in perl.

Any ideas?

+2  A: 

Seems pretty straightforward, something like this:

# Or whatever the column is really named ;)
my $dblinks = $dbh->selectcol_arrayref("select dbname from db_link");

for my $dblink (@$dblinks) {
  my $success = eval {
    my ($ret) = $dbh->selectrow_array("select 1 from "
      . $dbh->quote_identifier($dblink, undef, "dual") );
    $ret;
  };

  if ($success) {
    say "$dblink is up";
  } else {
    say "$dblink is down";
  }
}
hobbs
+1 for `quote_identifier()`. For pedantry points, I think the dynamic SQL should be: `"SELECT 1 FROM " . $dbh->quote_identifer('dual', undef, $dblink)`.
pilcrow
@pilcrow: Actually, you've got that backwards. It's ` $dbh->quote_identifier( 'link', 'schema', 'table' );` so it would be `"SELECT 1 FROM " . $dbh->quote_identifer($dblink, undef, 'dual')`.
cjm
@cjm, right-o: quote_identifier(cat, schem, tab).
pilcrow
@cjm @pilcrow thanks, improved.
hobbs
A: 

You have given me very useful advise and encourgages me to use perl further.

Lastly, how do i get all of the lines of "$dblink is down" into one $l_msg string. The $l_msg string would ideally contain the oracle error: i.e. $dblink is down with error $l_oraerror" and so on.

The hardest bit must be getting the error returned by oracle on failure. I cannot see a way to solve this.

Paul
Stack Overflow isn't a forum, and doesn't have conversation threads. You should start a new question for something like this.
cjm