在 oracle 中,如何更改会话以显示 UTF8?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1998771/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:19:31  来源:igfitidea点击:

In oracle, how do I change my session to display UTF8?

oracleutf-8

提问by Aaron Fi

I can't figure out Oracle's encryptic syntax for the life of me. This is Oracle 10g

我一生都无法弄清楚 Oracle 的加密语法。这是 Oracle 10g

My session's NLS_LANGUAGE is currently defaulting to AMERICAN. I need to be able to display UTF8 characters.

我的会话的 NLS_LANGUAGE 当前默认为 AMERICAN。我需要能够显示 UTF8 字符。

Below are some of my attempts, all incorrect:

以下是我的一些尝试,都是错误的:

ALTER SESSION SET NLS_LANGUAGE='UTF8'
ALTER SESSION SET NLS_LANGUAGE='AMERICAN_AMERICA.UTF8'

What's the secret command?

什么秘密命令?

采纳答案by APC

The character set is part of the locale, which is determined by the value of NLS_LANG. As the documentation makes clearthis is an operating system variable:

字符集是语言环境的一部分,由 的值决定NLS_LANG。正如文档所明确指出的,这是一个操作系统变量

NLS_LANGis set as an environment variable on UNIX platforms. NLS_LANGis set in the registry on Windows platforms.

NLS_LANG在 UNIX 平台上设置为环境变量。NLS_LANG在 Windows 平台上的注册表中设置。

Now we can use ALTER SESSIONto change the values for a couple of locale elements, NLS_LANGUAGE and NLS_TERRITORY. But not, alas, the character set. The reason for this discrepancy is - I think - that the language and territory simply effect how Oracle interprets the stored data, e.g. whether to display a comma or a period when displaying a large number. Wheareas the character set is concerned with how the client application renders the displayed data. This information is picked up by the client application at startup time, and cannot be changed from within.

现在我们可以使用ALTER SESSION来更改几个语言环境元素的值,NLS_LANGUAGE 和 NLS_TERRITORY。但不是,唉,字符集。这种差异的原因是 - 我认为 - 语言和地域只会影响 Oracle 解释存储数据的方式,例如,在显示大量数字时是否显示逗号或句点。而字符集与客户端应用程序如何呈现显示的数据有关。此信息由客户端应用程序在启动时获取,并且无法从内部更改。

回答by Aaron Fi

Okay, per http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm:

好的,根据http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm

NLS_LANG cannot be changed by ALTER SESSION, NLS_LANGUAGE and NLS_TERRITORY can. However NLS_LANGUAGE and /or NLS_TERRITORY cannot be set as "standalone" parameters in the environment or registry on the client.

NLS_LANG 不能被 ALTER SESSION 改变,NLS_LANGUAGE 和 NLS_TERRITORY 可以。但是,NLS_LANGUAGE 和/或 NLS_TERRITORY 不能在客户端的环境或注册表中设置为“独立”参数。

Evidently the "right" solution is, before logging into Oracle at all, setting the following environment variable:

显然,“正确”的解决方案是,在完全登录 Oracle 之前,设置以下环境变量:

export NLS_LANG=AMERICAN_AMERICA.UTF8

Oracle gets a big fat F for usability.

Oracle 在可用性方面获得了很大的 F。

回答by pahariayogi

Therefore, before starting '$ sqlplus' on OS, run the followings:

因此,在操作系统上启动 '$ sqlplus'之前,请运行以下命令:

  • On Windows

    set NLS_LANG=AMERICAN_AMERICA.UTF8

  • On Unix (Solaris and Linux, centos etc)

    export NLS_LANG=AMERICAN_AMERICA.UTF8

  • 在 Windows 上

    设置 NLS_LANG=AMERICAN_AMERICA.UTF8

  • 在 Unix(Solaris 和 Linux、centos 等)上

    导出 NLS_LANG=AMERICAN_AMERICA.UTF8

It would also be advisable to set env variable in your '.bash_profile' [on start up script]

还建议在您的“.bash_profile”中设置 env 变量 [在启动脚本时]

This is the place where other ORACLE env variables (ORACLE_SID, ORACLE_HOME) are usually set.

这是通常设置其他 ORACLE 环境变量(ORACLE_SID、ORACLE_HOME)的地方。

just fyi - SQL Developeris good at displaying/handling non-English UTF8 characters.

仅供参考 - SQL Developer擅长显示/处理非英语 UTF8 字符。