Oracle 中的 NLS_CHARACTERSET WE8ISO8859P1 和 UTF8 问题

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

NLS_CHARACTERSET WE8ISO8859P1 and UTF8 issues in Oracle

javaoracle

提问by user958573

I am currently using a Database in oracle which has NLS_CHARACTERSET WE8ISO8859P1 so lets say I store a value in varchar2 field which is ma? (accented character) so in database it gets stored as ma?? . Now when I try to retrieve it with query select * from table where fieldValue = 'ma?' it returns 0 rows, and then when i try to insert it again it gives me a constraint error saying value already exist.

我目前在 oracle 中使用一个数据库,它有 NLS_CHARACTERSET WE8ISO8859P1 所以可以说我在 varchar2 字段中存储了一个值,它是 ma?(重音字符)所以在数据库中它被存储为 ma?? . 现在,当我尝试使用查询 select * from table where fieldValue = 'ma?' 检索它时 它返回 0 行,然后当我尝试再次插入它时,它给了我一个约束错误,说值已经存在。

How to overcome such situation. I am doing this via Java code

如何克服这种情况。我正在通过 Java 代码执行此操作

采纳答案by Multisync

http://docs.oracle.com/cd/B19306_01/server.102/b14225/ch2charset.htm#g1009784

http://docs.oracle.com/cd/B19306_01/server.102/b14225/ch2charset.htm#g1009784

Oracle Character Set Name: WE8ISO8859P1
Description: Western European 8-bit ISO 8859 Part 1
Region: WE (Western Europe)
Number of Bits Used to Represent a Character: 8

Oracle 字符集名称:WE8ISO8859P1
描述:西欧 8 位 ISO 8859 第 1 部分
区域:WE(西欧)
用于表示字符的位数:8

On the other hand, UTF-8 uses several bytes to store a symbol.

另一方面,UTF-8 使用几个字节来存储一个符号。

If your database uses WE8ISO8859P1 and the column type is from VARCHAR group (not NVARCHAR) and you're inserting a symbol which code > 255, this symbol will be transformed to WE8ISO8859P1 and some information will be lost.

如果您的数据库使用 WE8ISO8859P1 并且列类型来自 VARCHAR 组(不是 NVARCHAR),并且您插入的符号代码 > 255,则该符号将转换为 WE8ISO8859P1 并且一些信息将丢失。

To put it simply, if you're inserting UTF-8 into a db with single-byte character set, your data is lost.

简而言之,如果您将 UTF-8 插入到具有单字节字符集的数据库中,您的数据就会丢失。

The link above describes different scenarios how to tackle this issue.

上面的链接描述了如何解决这个问题的不同场景。

You can also try Oracle asciistr/unistrfunctions, but in general it's not a good way to deal with such problems.

也可以试试oracle asciistr/ unistrfunctions,但一般来说不是很好的处理此类问题的方法。