周傑倫 金載沅 gabriella fox
將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;
}
PHA979while($conn->FetchRow()){
my @dataRow = $conn->Data();
##INSERT 資料至MySQL
my $str="INSERT INTO aTABLE VALUES ('".$dataRow[0]."')";
$str = encode("utf8",decode("big5",$str));
my $row老房子s = $dbh->do($str);
}
$dbh->disconnect();
$conn->Close();
沒有留言:
張貼留言