Perl、DBD::Oracle 和 Oracle 10g 的字符集问题
我们遇到了一个问题,基本 ASCII 集之外的字符在 Oracle 10g 数据库中显示为颠倒的问号。
我有以下脚本来加载一些测试数据。该脚本在 Komodo IDE 的远程 UNIX 服务器上保存为 Latin-1/ISO-8859-1:
#!/wload/espd/app/perl/bin/perl
use strict;
use warnings;
use Encode;
use esp_libs_db;
my $dbh = espDbConnectNew();
my $sql = q{ INSERT INTO DBUSER.test VALUES ('qwérty')};
#$sql = encode("iso-8859-1", $sql);
my $rows = $dbh->do($sql) or Carp::croak "ERROR: PM_DB_0010:[" . $DBI::errstr . "] Cannot run stmt:\n";;
print $rows;
$dbh->commit();
$dbh->disconnect();
sub espDbConnectNew {
my ( $database ) = @_;
my %connectionStrings = &esp_libs_db::espGetConnectionStrings( $database );
# Set Environment Variables
$ENV{ORACLE_SID}=$connectionStrings{"SID"};
$ENV{ORACLE_HOME}=$connectionStrings{"HOME"};
my $dbh = DBI->connect("dbi:Oracle:SID=$connectionStrings{'SID'};HOST=$connectionStrings{'HOST'};PORT=$connectionStrings{'PID'}",
"$connectionStrings{'USER'}","$connectionStrings{'PWD'}",
{PrintError=>0,
RaiseError => 0,
AutoCommit => 0}
) or Carp::croak "ERROR: PM_DB_0003: Cant connect to db:\n";
return $dbh;
} #espDbConnect
它加载到的数据库是 Oracle 10g 数据库,具有以下参数:
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_LANGUAGE ENGLISH
NLS_TERRITORY UNITED KINGDOM
NLS_CHARACTERSET WE8ISO8859P1
测试表上的单个列的类型为 VARCHAR2( 255)。
尽管花了整整一天的时间阅读这些问题,但我真的不知道该怎么做才能解决/诊断确切的问题。
我在执行 SQL 字符串之前尝试过使用和不使用 Encode 对 SQL 字符串进行编码。
谢谢
We have a problem with characters outside of the basic ASCII set appearing as upside down question marks in our Oracle 10g database.
I have the following script to load some test data. The script is saved as Latin-1/ISO-8859-1 on a remote UNIX server from Komodo IDE:
#!/wload/espd/app/perl/bin/perl
use strict;
use warnings;
use Encode;
use esp_libs_db;
my $dbh = espDbConnectNew();
my $sql = q{ INSERT INTO DBUSER.test VALUES ('qwérty')};
#$sql = encode("iso-8859-1", $sql);
my $rows = $dbh->do($sql) or Carp::croak "ERROR: PM_DB_0010:[" . $DBI::errstr . "] Cannot run stmt:\n";;
print $rows;
$dbh->commit();
$dbh->disconnect();
sub espDbConnectNew {
my ( $database ) = @_;
my %connectionStrings = &esp_libs_db::espGetConnectionStrings( $database );
# Set Environment Variables
$ENV{ORACLE_SID}=$connectionStrings{"SID"};
$ENV{ORACLE_HOME}=$connectionStrings{"HOME"};
my $dbh = DBI->connect("dbi:Oracle:SID=$connectionStrings{'SID'};HOST=$connectionStrings{'HOST'};PORT=$connectionStrings{'PID'}",
"$connectionStrings{'USER'}","$connectionStrings{'PWD'}",
{PrintError=>0,
RaiseError => 0,
AutoCommit => 0}
) or Carp::croak "ERROR: PM_DB_0003: Cant connect to db:\n";
return $dbh;
} #espDbConnect
The database it loads into is an Oracle 10g database with the following parameters:
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_LANGUAGE ENGLISH
NLS_TERRITORY UNITED KINGDOM
NLS_CHARACTERSET WE8ISO8859P1
The single column on the test table is of type VARCHAR2(255).
Despite a full working day reading about these problems I don't really know what to do to solve/diagnose the exact problem.
I've tried this both with and without using Encode to encode the SQL string before executing it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当你得到倒置的问号时,你如何检索数据?您检索数据的客户端上的 NLS_LANG 环境变量是什么?
在 SQL*Plus 中,您可以运行
并发布结果吗? DUMP 函数显示数据库中实际存储的内容,这将显示问题是在存储重音字符还是在检索重音字符时出现问题。
How are you retrieving the data when you get the upside down question marks? What is the NLS_LANG environment variable on the client where you are retrieving the data?
In SQL*Plus, can you run
and post the results? The DUMP function shows what is actually stored in the database-- that will show whether the problem is in storing the accented character or whether the problem is in retrieving the accented character.