將ORACLE的資料轉至MySQL
ORACLE為繁體中文,perl以ODBC連接
MySQL為utf8

use Win32::ODBC;
use DBI;
use Encode;

##連接ORACLE
if(!($conn = new Win32::ODBC("DSN=資料來源名稱;UID=帳號;PWD=密碼"))){
print "Error: " . Win32::ODBC::Error();
exit();
}

##連接MYSQL
my $dbh = DBI->connect("DBI:mysql:database=資料庫;host=localhost","帳號","密碼", {'RaiseError' => 1});
$dbh->do("set character set utf8");

##SELECT ORACLE資料表
$SQL = "SELECT * FROM mytable";
if($conn->Sql($SQL)){
print "I could not execute the following statement:\n $SQL\n";
print "$conn->Error() \n";
$conn->Close();
die;
}
while($conn->FetchRow()){
my @dataRow = $conn->Data();
##INSERT 資料至MySQL
my $str="INSERT INTO aTABLE VALUES ('".$dataRow[0]."')";
$str = encode("utf8",decode("big5",$str));
my $rows = $dbh->do($str);
}

$dbh->disconnect();
$conn->Close();

jck11 發表在 痞客邦 PIXNET 留言(2) 人氣()


留言列表 (2)

發表留言
  • claudea26
  • 幫你推推,互相推推
  • 郭振函
  • 欣賞你的文章是我的榮幸