Oracle PL/SQL 中的字符编码问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12440077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Character encoding issue in Oracle PL/SQL
提问by prashant1988
I'm facing a character discrepancy issue while extracting data from db tables.
从数据库表中提取数据时,我遇到了字符差异问题。
I've written a PL/SQL code to spool some data to .txt file from my db tables and running this sql using unix shell but when I'm getting the spooled file, the result set is a changed one from the one at back end.
我已经编写了一个 PL/SQL 代码来将一些数据从我的 db 表中假脱机到 .txt 文件并使用 unix shell 运行这个 sql 但是当我得到假脱机文件时,结果集是从后面的那个改变的结尾。
For example:
例如:
At back end: SADETTYN
In Spooled txt file : SADETT?N
If you look at the Y
character, it is a changed one. I want to preserve all the characters the way they are at back end.
如果你看这个Y
角色,它是一个改变的角色。我想保留所有字符在后端的方式。
My db's character set:
我的数据库的字符集:
SELECT * FROM v$nls_parameters WHERE parameter LIKE 'NLS%CHARACTERSET'
PARAMETER VALUE
NLS_CHARACTERSET WE8ISO8859P1
NLS_NCHAR_CHARACTERSET WE8ISO8859P1
And Unix NLS_LANG parameter :
和 Unix NLS_LANG 参数:
$ echo $NLS_LANG
AMERICAN_AMERICA.WE8ISO8859P1
I tried changing NLS_LANG parameter to WE8ISO8859P9(Trukish characterset) but no help!
我尝试将 NLS_LANG 参数更改为 WE8ISO8859P9(土耳其语字符集),但没有帮助!
Could anyone let me know the solution to this problem?
谁能让我知道这个问题的解决方案?
回答by BulentB
I presume that you are trying to visualize your file with "vi" or something similar.NLS_LANG parameter is used only by your database to export to your file.For your editor(vi), you need to set the LANG parameter to the corresponding value to your NLS_LANG. Exemple : For ISO8859P1 american english you have to do export LANG=en_US.ISO8859-1 In other words your file is just fine it's your editor who doesn't know what to do with your Turkish characters.
我假设您正在尝试使用“vi”或类似的东西来可视化您的文件。NLS_LANG 参数仅由您的数据库用于导出到您的文件。对于您的编辑器(vi),您需要将 LANG 参数设置为相应的值到您的 NLS_LANG。示例:对于 ISO8859P1 美国英语,您必须执行 export LANG=en_US.ISO8859-1 换句话说,您的文件很好,是您的编辑器不知道如何处理您的土耳其语字符。
回答by Geordee Naliyath
You should use NCHAR data types. More information is available at Oracle Documentation - SQL and PL/SQL Programming with Unicode
您应该使用 NCHAR 数据类型。更多信息可在 Oracle 文档 - SQL 和 PL/SQL 使用 Unicode 编程
For spooling from SQL*Plus, you need to set the NLS_LANG environment variable correctly. Here is a similar question in stackoverflow.
对于从 SQL*Plus 进行假脱机,您需要正确设置 NLS_LANG 环境变量。这是stackoverflow 中的一个类似问题。