DB2 UTF-8编码:Umlaut转换为CHAR(1)? [英] DB2 UTF-8 encoding: Umlaut to CHAR(1)?
问题描述
UTF-8编码的DB2数据库中的"CHAR(1)"是什么意思?
What does "CHAR(1)" in a UTF-8 encoded DB2 database mean?
我可以在CHAR(1)的列中插入一个特殊字符(例如,在UTF-8中使用2个八位位组的字符)吗?
Can I insert a special character (e.g. one that takes 2 octets in UTF-8) into a column of CHAR(1)?
还是UTF-8中的CHAR(1)总是意味着它具有一个字节/八位位组的容量,即,将Umlaut插入其中会失败吗?
Or does CHAR(1) in UTF-8 always mean, that it has capacity for one byte / octet, i.e. such that inserting an Umlaut into it will fail ?
我阅读了这篇有趣的 developerWorks 文章,但这对我的简单问题来说很深...
I read through this interesting developerWorks article, but it's going to deep for my simple question...
推荐答案
这要视情况而定. :)
It depends. :)
DB2引入了code units
来帮助设计基于字符数而不是字节数的字符串类型的列. CREATE TABLE
语句概述了数据类型,并解释了CHAR
和VARCHAR
.如果使用字符数,则DB2假定最坏的情况-每个字符4个字节/八位字节-用于长度计算.
DB2 introduced code units
to help with designing string-typed columns that are based on number of characters and not number of bytes. The CREATE TABLE
statement has an overview of data types and also explains CHAR
and VARCHAR
. If number of characters is used, DB2 is assuming the worst case - 4 bytes/octets per character - for length computations.
数据库配置 string_units
确定默认情况下是否考虑字符数(CODEUNITS32
)或字节数(SYSTEM
).
The database configuration string_units
determines whether by default the number of characters (CODEUNITS32
) or the number of bytes (SYSTEM
) is considered.
回到您的问题:如果您未指定任何内容,则将需要2个八位位组的特殊字符插入CHAR(1)可能会失败.如果指定了CODEUNITS32,则它将成功.
Coming back to your question: If you did not specify anything, inserting a special character that needs 2 octets into a CHAR(1) will likely fail. If CODEUNITS32 was specified, then it will succeed.
这篇关于DB2 UTF-8编码:Umlaut转换为CHAR(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!