1
我想讀在Oracle表包含數據庫鏈接檢查每個數據庫鏈接的可用性和每個數據庫鏈接返回只有不好的結果的查找表的每個條目和錯誤消息。使用Perl選擇1從@ db_link其中db_link來自
欲該查找表中提取到一個數組,並且從dualQdb_link通過db_link的條目到選擇,測試查找的所有條目來測試的成功或失敗。這在perl中很難實現。
任何想法?
我想讀在Oracle表包含數據庫鏈接檢查每個數據庫鏈接的可用性和每個數據庫鏈接返回只有不好的結果的查找表的每個條目和錯誤消息。使用Perl選擇1從@ db_link其中db_link來自
欲該查找表中提取到一個數組,並且從dualQdb_link通過db_link的條目到選擇,測試查找的所有條目來測試的成功或失敗。這在perl中很難實現。
任何想法?
似乎很簡單,這樣的事情:
# 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";
}
}
+1'quote_identifier()'。對於pedantry點,我認爲動態SQL應該是:''SELECT 1 FROM'。 $ dbh-> quote_identifer('dual',undef,$ dblink)'。 – pilcrow 2010-02-28 02:09:54
@pilcrow:其實,你已經倒過來了。這是'$ dbh-> quote_identifier( '鏈接', '模式', '表');'所以這將是' 「SELECT 1 FROM」。 $ dbh-> quote_identifer($ dblink,undef,'dual')'。 – cjm 2010-02-28 08:33:57
@cjm,right-o:quote_identifier(cat,schem,tab)。 – pilcrow 2010-02-28 15:20:31