我正在编写一个 perl 脚本来使用 mysql 数据库中的数据更新 oracle 数据库中的表。
我是 perl 的新手,所以任何帮助将不胜感激。
我目前有以下内容,它不会更新 oracle 数据库,但也不会引发任何错误。
数据库都已初始化。
我希望 oracle tblrecommendations 表使用 mysql tblrecommendations 表中的内容更新性能。
提前致谢。
#transfer data
sub do_crc_company_performance {
my ($sth_mysql, $sth_oracle);
my $sql_details = <<END_SQL;
select
tblRecommendations.code,
tblRecommendations.performance
from
crc.tblRecommendations
where
length(tblRecommendations.code) = '3'
END_SQL
# variables to bind values to
my ($code, $performance);
eval {
# prepare our select statement for mysql
$sth_mysql = $dbh_mysql->prepare($sql_details);
$sth_mysql->execute;
$sth_mysql->bind_columns(\($code, $performance));
# create oracle insertion query
$sth_oracle = $dbh_oracle->prepare(q{UPDATE TBLRECOMMENDATIONS
SET PERFORMANCE = '$performance'
WHERE CODE = '$code'});
while ( $sth_mysql->fetch ) {
$performance = Encode::decode_utf8($performance); # set the flag
# feed the data into the tblRecommendations table
$sth_oracle->execute();
}
};
if ($@) {
# what went wrong
push (@errors, "Unable to update company details: $@");
# rollback our transaction
$dbh_oracle->rollback()
}
$sth_oracle->finish if ($sth_oracle);
$sth_mysql->finish if ($sth_mysql);
}