473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

The length of CHAR() and CLOB columns in UTF8 character set

Hi,

I was wondering if anyone could advise me on this.

Right now I am setting up a DB2 UDB V8.2.3 database with UTF8
character set, which will work with a J2EE application running on
WebSphere Application Server.

I have two questions:
1. How many characters, such as Chinese, Japanese, can a CHAR(128) or
CLOB(4000) column take? From the DB2 document, it looks that the
CHAR(128) means 128 bytes, instead of 128 characters. Since some double
type characters may take up to 3 bytes in UTF8, a CHAR(128) can only
store 40 ( 1/3 of 128) characters. Is there a easier way to tell how
many characters a CHAR or CLOB column can take?

And interstingly, I happened to see that in Oracle the environment
varialble NLS_LENGTH_SEMANTICS = 'CHAR' can guarantee the CHAR(128)
holds 128 characters at the database level. And it also support a
modifier, such as CHAR(128 char), to specify at column level. Please
correct me if I am wrong. But I was just wondering would it be nice if
DB2 provides the same feature.

2. From performance's point of view, should I set DB2 character set
UTF8 or UTF16? Since Java uses only UTF16, does that mean that the java
program or JDBC has to do converstion for each character?

Any comments are highly appreciated!
Jason Zhang

Dec 5 '06 #1
2 10246
Jason,
Your understanding is correct. In DB2, CHAR(128) is 128 bytes, which
for Chinese characters will be a little over 40 characters. If you
store English data in that column, it will hold 128 characters, since
they take 1 byte per character. And, I agree, it would be nice if there
were an option to specify characters rather than bytes.
One solution, to hold enough characters is to make the column VARCHAR
and large enough for the number of characters you need (e.g.
VARCHAR(384) in this case). But, the application would have to ensure
that no more than 128 characters were entered if that is what you want.
As for UTF8 vs UTF16, it is true that there would be some conversion
for Java, but I personally would not worry about too much. If you have
Java programs currently accessing non-unicode tables, you're getting
that conversion today. Note that in UTF16, most Chinese characters are
2 bytes, as are all English characters. So, spacewise, it depends on
what languages you plan to mostly store.

Joe
Jason wrote:
Hi,

I was wondering if anyone could advise me on this.

Right now I am setting up a DB2 UDB V8.2.3 database with UTF8
character set, which will work with a J2EE application running on
WebSphere Application Server.

I have two questions:
1. How many characters, such as Chinese, Japanese, can a CHAR(128) or
CLOB(4000) column take? From the DB2 document, it looks that the
CHAR(128) means 128 bytes, instead of 128 characters. Since some double
type characters may take up to 3 bytes in UTF8, a CHAR(128) can only
store 40 ( 1/3 of 128) characters. Is there a easier way to tell how
many characters a CHAR or CLOB column can take?

And interstingly, I happened to see that in Oracle the environment
varialble NLS_LENGTH_SEMANTICS = 'CHAR' can guarantee the CHAR(128)
holds 128 characters at the database level. And it also support a
modifier, such as CHAR(128 char), to specify at column level. Please
correct me if I am wrong. But I was just wondering would it be nice if
DB2 provides the same feature.

2. From performance's point of view, should I set DB2 character set
UTF8 or UTF16? Since Java uses only UTF16, does that mean that the java
program or JDBC has to do converstion for each character?

Any comments are highly appreciated!
Jason Zhang
Dec 10 '06 #2
Joe Geller wrote:
One solution, to hold enough characters is to make the column VARCHAR
and large enough for the number of characters you need (e.g.
VARCHAR(384) in this case). But, the application would have to ensure
that no more than 128 characters were entered if that is what you want.
You could write a UDF and use it in a constraint on the table/column in
question. Then you have the integrity ensured at the database level.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Dec 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sinasalek | last post by:
i have a problem with MySQL 4.1.x and UTF8. in version 4.0, i'm using html forms with utf8 charset for inserting unicode strings. but in version 4.1.x it is not working! if i change the charset of...
3
by: kieran | last post by:
Hi, I'm using fstream.get to read in a character from a file, then print it on the screen. I have a file called test.log that contains "Hello, World!", but when I try and print the contents out on...
2
by: Jim | last post by:
All of a sudden I am unable to create tables or add columns to existing tables if I specify CHARACTER greater than 254. If I try I get the following error: DB21034E The command was processed as...
3
by: Daniel Rimmelzwaan | last post by:
Does anyone know how to convert a (char)02 into a UTF8 string that I can put into an XML element? I've tried all examples that I could find in Visual Studio help or in google, but I can't get it to...
2
by: bob | last post by:
I am binding a datatable to a datagrid in VB.NET I then want to change the width of the first column. I am unable to get the right syntax. Here is the code I tried Dim mydataset As DataSet...
0
by: aniendow | last post by:
Hi All, I am trying to upload a TAB delimited file into a database table. Considering the performance issue I thought EXTERNAL TABLE is my best option but with one problem, My table has CLOB...
0
by: motykosh | last post by:
Hi, I'm using DB2 V9.1 and php on a redhat 4 64Bit production server. When I take a backup from that server and restore it on a 64Bit ubuntu 7.04 server with the same version of DB2 and PHP, the...
5
by: codeGhost | last post by:
I've been trying to ignore this issue for a while now, but I've come to the point in my code where I can't do so anymore. (For those of you who are wondering, this is NOT a homework question). ...
6
by: TTheot | last post by:
Hallo everyone. I am trying to call an unmanaged C++ function, that has a structure as an input parameter. The structure is defined in the header file like this: struct MyStruct { int ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.