我在Solaris上的oracle 10数据库中插入UTF8字符串时遇到了一些麻烦,在perl v5.8.4上使用了最新的DBD :: Oracle。
这是我的数据库设置
> --------SELECT * from NLS_DATABASE_PARAMETERS-------------------------------
> NLS_NCHAR_CHARACTERSET AL16UTF16
> NLS_LANGUAGE AMERICAN
> NLS_TERRITORY AMERICA NLS_CURRENCY $
> NLS_ISO_CURRENCY AMERICA
> NLS_NUMERIC_CHARACTERS .,
> NLS_CHARACTERSET UTF8
> NLS_CALENDAR GREGORIAN
> NLS_DATE_FORMAT DD-MON-RR
> NLS_DATE_LANGUAGE AMERICAN
> NLS_SORT BINARY
> NLS_TIME_FORMAT HH.MI.SSXFF AM
> NLS_TIMESTAMP_FORMAT DD-MON-RR
> HH.MI.SSXFF AM
> NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
> NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR
> HH.MI.SSXFF AM TZR NLS_DUAL_CURRENCY $
> NLS_COMP BINARY
> NLS_LENGTH_SEMANTICS CHAR
> NLS_NCHAR_CONV_EXCP FALSE
> NLS_RDBMS_VERSION 10.2.0.4.0
> --------------------------------------------------------------------------
这是我的perl $ dbh-> ora_nls_parameters()
$VAR1 = {
'NLS_LANGUAGE' => 'AMERICAN',
'NLS_TIME_TZ_FORMAT' => 'HH.MI.SSXFF AM TZR',
'NLS_SORT' => 'BINARY',
'NLS_NUMERIC_CHARACTERS' => '.,',
'NLS_TIME_FORMAT' => 'HH.MI.SSXFF AM',
'NLS_ISO_CURRENCY' => 'AMERICA',
'NLS_COMP' => 'BINARY',
'NLS_CALENDAR' => 'GREGORIAN',
'NLS_DATE_FORMAT' => 'DD-MON-RR',
'NLS_DATE_LANGUAGE' => 'AMERICAN',
'NLS_TIMESTAMP_FORMAT' => 'DD-MON-RR HH.MI.SSXFF AM',
'NLS_TERRITORY' => 'AMERICA',
'NLS_LENGTH_SEMANTICS' => 'CHAR',
'NLS_NCHAR_CHARACTERSET' => 'AL16UTF16',
'NLS_DUAL_CURRENCY' => '$',
'NLS_TIMESTAMP_TZ_FORMAT' => 'DD-MON-RR HH.MI.SSXFF AM TZR',
'NLS_NCHAR_CONV_EXCP' => 'FALSE',
'NLS_CHARACTERSET' => 'UTF8',
'NLS_CURRENCY' => '$'
};
在我的剧本中我有:
use utf-8;
$ENV{NLS_LANG}='AMERICAN_AMERICA.UTF8';
..
$sth->bind_param(5, $myclobfield, {ora_type => ORA_CLOB, ora_csform => SQLCS_NCHAR});
..
字符串在
上打印出1print Encode::is_utf8($myclobfield);
但是像òàè这样的字符没有正确插入数据库。 (我使用符合utf8标准的客户端测试,可以正确插入和读取它们)
有人能建议最好的方法吗? 感谢
答案 0 :(得分:1)
经过几个小时的锤击,并且篡改了所有的DBA,我解决了它:
我错过了这个:
$ENV{NLS_NCHAR}='AL32UTF16';
也要小心
utf8::encode($myclobfield);
如果您不确定它是UTF8
干杯 -G。
答案 1 :(得分:0)
Unicode文字需要以'n'为前缀,如下所示:
从双重选择n'Language - Språk - Język';
另外,请检查:Inserting national characters into an oracle NCHAR or NVARCHAR column does not work