If we have US7ASCII characterset why does it let us store non-ascii characters?

前端 未结 2 867
名媛妹妹
名媛妹妹 2020-12-21 19:29

We have an Oracle database that has the NLS_CHARACTERSET = US7ASCII.

As a test, we ran an insert into a table that contains a VARCHAR(4000)

相关标签:
2条回答
  • 2020-12-21 19:47

    The database allows that value to be stored because Oracle will handle the character set conversion for you.

    More info can be found here: Special Characters in Oracle

    0 讨论(0)
  • 2020-12-21 19:50

    It works because following conditions are both true:

    • Client character set is equal to your database character set.
    • The character set permits any byte values

    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 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 ?.

    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.

    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.

    0 讨论(0)
提交回复
热议问题