问题描述
我目前在oracle中使用了一个具有NLS_CHARACTERSET WE8ISO8859P1的数据库,所以我想在varchar2字段中存储一个值为maž(重音字符),因此在数据库中它存储为maå¾。现在,当我尝试使用查询select * from table from fieldValue ='maž'检索它时,它返回0行,然后当我尝试再次插入它时,它给出了一个约束错误,表示值已经存在。
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.
如何克服这种情况。
我通过Java代码执行此操作
How to overcome such situation. I am doing this via Java code
推荐答案
另一方面,UTF-8使用几个字节来存储符号。
On the other hand, UTF-8 uses several bytes to store a symbol.
如果您的数据库使用WE8ISO8859P1且列类型为来自VARCHAR组(不是NVARCHAR)并且您正在插入代码> 255的符号,此符号将转换为WE8ISO8859P1并且某些信息将丢失。
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.
要放简单地说,如果你将UTF-8插入到具有单字节字符集的数据库中,你的数据就会丢失。
To put it simply, if you're inserting UTF-8 into a db with single-byte character set, your data is lost.
上面的链接描述了如何解决此问题的不同方案。
The link above describes different scenarios how to tackle this issue.
您还可以尝试Oracle asciistr
/ unistr
函数,但一般来说它不是处理此类问题的好方法。
You can also try Oracle asciistr
/unistr
functions, but in general it's not a good way to deal with such problems.
这篇关于Oracle中的NLS_CHARACTERSET WE8ISO8859P1和UTF8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!