如果我们有US7ASCII字符集,为什么要让我们存储非ASCII字符? [英] If we have US7ASCII characterset why does it let us store non-ascii characters?
问题描述
我们有一个具有NLS_CHARACTERSET = US7ASCII
的Oracle数据库.
We have an Oracle database that has the NLS_CHARACTERSET = US7ASCII
.
作为测试,我们在包含VARCHAR(4000)
字段的表中插入了一个插入内容,以便能够在该列(degrees symbol
)中放置CHR(176)
值.
As a test, we ran an insert into a table that contains a VARCHAR(4000)
field as were able to put a CHR(176)
value in that column (degrees symbol
).
US7ASCII
似乎不支持该字符.
为什么数据库会允许将该值存储在该列中?
Why would the database allow that value to be stored in that column?
推荐答案
之所以可行,是因为以下条件都成立:
It works because following conditions are both true:
- 客户端字符集等于您的数据库字符集.
- 字符集允许任何字节值
您的数据库字符集和客户字符集设置为US7ASCII
.在这种情况下,无需进行任何转换就可以逐个写入/读取每个数据,即将您发送的字节准确地写入数据库.可能您根本没有在客户端设置NLS_LANG
,但是Oracle默认将其设置为AMERICAN_AMERICA.US7ASCII
.
Your database character set and your client character set are set to US7ASCII
. In such case each data is written/read one by one without any conversion, i.e. the bytes you send are exactly written to database. Probably you did not set NLS_LANG
at all on your client side but Oracle defaults it to AMERICAN_AMERICA.US7ASCII
.
US7ASCII
是7位编码.我假设一个纯ASCII应用程序(可能很难找到)只会忽略存储在8位体系结构中的第8位.其他字符集,例如AL32UTF8
不允许每个字节值.在这种情况下,此类字符将被占位符替换,例如¿
或?
.
US7ASCII
is a 7-bit encoding. I assume a pure ASCII application (which could be fairly difficult to find) would just ignore the 8th bit which is stored in an 8-Bit architecture. Other character sets, e.g. AL32UTF8
do not allow each byte value. In this case such characters will be replaced by a placeholder, e.g. ¿
or ?
.
注意,您将客户字符集设置为US7ASCII
,这很可能是不正确的.将其正确设置为应用程序使用的字符集,然后将替换°
.
Note, you set your client character set to US7ASCII
which is most likely not correct. Set it properly to the character set which is used by your application, then °
will get replaced.
如果您使用带有命令chcp
的SQL * Plus检查控制台代码页,请分别. locale charmap
.在启动sqlplus之前,相应地设置NLS_LANG
环境变量.
In case you use SQL*Plus check console codepage with command chcp
, resp. locale charmap
. Set your NLS_LANG
environment variable accordingly before you start sqlplus.
这篇关于如果我们有US7ASCII字符集,为什么要让我们存储非ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!