调试经验——ORA-29275: partial multibyte character的解决方案

问题描述:

有个生产报表运行失败,报错:ORA-29275: partial multibyte character。借助百度、Google前前后后试过多种方法,解决不掉。

后来,想到是否可以更改注册表中的NLS_LANG选项,问题还真解决了。

详细解决方案:

最简方案:

1. 添加系统环境变量NLS_LANG,赋值为AMERICAN_AMERICA.AL32UTF8

2. 无需重启电脑,新建一个SQLPLUS会话,发现query已可正常运行,而不会报错:ORA-29275: partial multibyte character

 

以下方法需改动注册表,比较麻烦,处于安全考虑,慎用。

1. 在注册表中修改Oracle NLS_LANG选项(需管理员权限):

路径:Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\oracle\KEY_OraClient11g_home1_32bit

NLS_LANG的当前值为:AMERICAN_AMERICA.WE8MSWIN1252,将其修改为:AMERICAN_AMERICA.AL32UTF8

2. 重启电脑

3. 使用SQLPLUS运行相同的脚本(Toad中不行,原因未知),不再报错,可成功查询出结果

 

补充说明:

能够找到百度、Google中也没有的解决方案,还是挺有成就感的!

----------------------------------------------------------------------------------------------------------------------------------------

延伸阅读:

ORA-29275: partial multibyte character

Cause: The requested read operation could not complete because a partial multibyte character was found at the end of the input.

Action: Ensure that the complete multibyte character is sent from the remote server and retry the operation. Or read the partial multibyte character as RAW.

The core issue of that the nls_chracterset values for the multibyte character set does not match between either two databases in a distributed query, or a query where the webserver has a different character set.  There are several possible fixes for the ORA-29275 error, all involving getting the NLS character sets to match:

1 - write a function to convert each row.  Place this function inside a PL/SQL function and call it for each row of the table:
CONVERT(COLUMN NAME,'NLS_CHARACTERSET','NLS_CHARACTERSET');

2 - If you have a webserver, try setting the NLS_LANG environmental variable on the webserver to american_america.al32utf8.

Locale-Specific Settings
特定于区域的设置
A locale is a linguistic and cultural environment in which a system or program is running. NLS parameters determine locale-specific behavior on both the client and database. A database session uses NLS settings when executing statements on behalf of a client. For example, the database makes the correct territory usage of the thousands separator for a client.
区域设置是某个系统或程序正在其中运行的语言和文化环境。由NLS参数确定客户端和数据库所在的特定区域的行为。执行客户端语句时,数据库会话使用NLS设置。例如,数据库为客户端使用正确的千位分隔符区域用法。
Typically, the NLS_LANG environment variable on the client host specifies the locale for both the server session and client application. The process is as follows:
通常,由客户机主机上的 NLS_LANG 环境变量,指定服务器会话和客户端应用程序的区域设置。该过程如下所示:
 1. When a client application starts, it initializes the client NLS environment from the environment settings.
 1. 当客户端应用程序启动时,它根据其环境设置初始化客户端NLS环境。
All NLS operations performed locally, such as displaying formatting in Oracle Developer applications, use these settings.
所有NLS操作都在本地执行,例如,在 Oracle Developer应用程序中使用这些设置的显示格式。
 2. The client communicates the information defined by NLS_LANG to the database when it connects.
 2. 当客户端与数据库连接并进行通信时,使用由 NLS_LANG定义的信息格式。
 3. The database session initializes its NLS environment based on the settings communicated by the client.
 3. 数据库会话基于客户端的通信设置,初始化其NLS环境。
If the client did not specify settings, then the session uses the settings in the initialization parameter file. The database uses the initialization parameter settings only if the client did not specify any NLS settings. If the client specified some NLS settings, then the remaining NLS settings default.
如果客户端没有指定设置,则会话使用初始化参数文件中的设置。仅当客户端未指定任何NLS设置时,数据库才会使用初始化参数设置。如果客户端指定了某些NLS设置,则其余的NLS设置将保持默认值。
Each session started on behalf of a client application may run in the same or a different locale as other sessions. For example, one session may use the German locale while another uses the French locale. Also, each session may have the same or different language requirements specified.
每个为客户端应用程序启动的会话,可能与其他会话运行在相同或不同的区域设置。例如,一个会话可能会使用德语区域设置,而另一个可能会使用法语区域设置。每个会话还可能指定了相同或不同的语言要求。
Table 19-1 shows two clients using different NLS_LANG settings. A user starts SQL*Plus on each host, logs on to the same database as hr, and runs the same query simultaneously. The result for each session differs because of the locale-specific NLS setting for floating-point numbers.
表 19-1 显示了使用不同 NLS_LANG 设置的两个客户端。用户在每台主机上启动 SQL*Plus以hr登录到同一数据库,并同时运行相同的查询。由于对于浮点数的特定于区域设置的NLS设置不同,每个会话的结果有所不同。

调试经验——ORA-29275: partial multibyte character的解决方案_第1张图片

 

你可能感兴趣的:(数据库(DB))