By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,004 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,004 IT Pros & Developers. It's quick & easy.

Count Unicode characters in DB2 8

P: n/a
Hi,

I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.

Can anybody help me with that?

Thanks in advance
kind regards
Michael

Nov 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
globomike wrote:
I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.
I would write a simple Java UDF that takes the string as input and counts
the number of characters. Something like this (completely untested) should
do:

import java.lang.*; // for String class
import COM.ibm.db2.app.UDF; // UDF classes

public class UnicodeCharCount extends UDF
{
public void charCount(String str, int count) throws Exception
{
if (str != null) {
set(2, str.length());
}
}
}

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Nov 14 '07 #2

P: n/a
Hi!

Maybe something in the lines of:
VALUES(LENGTH(VARGRAPHIC('YOUR_UNICODE_STRING')))

Best regards,
Kovi

globomike wrote:
Hi,

I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.

Can anybody help me with that?

Thanks in advance
kind regards
Michael
--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Nov 14 '07 #3

P: n/a
Hi Kovi,

thanks that is what I need.
I tried it before but somehow got an error - something like
incompatible datatypes for the function...
Now I tried it again after you posted that solution and it works!

Thanks again
kindregards
Michael

On Nov 14, 4:49 pm, Gregor Kova <gregor.ko...@mikropis.siwrote:
Hi!

Maybe something in the lines of:
VALUES(LENGTH(VARGRAPHIC('YOUR_UNICODE_STRING')))

Best regards,
Kovi

globomike wrote:
Hi,
I am looking for a function (or hint) how I can count unicode
characters (and not bytes) in DB2 V8.2.
In DB2 9 the length function is extenced with the codeunits32 option -
and this is exactly what I need in DB2 V8.2.
Can anybody help me with that?
Thanks in advance
kind regards
Michael

--
____________________________
|http://kovica.blogspot.com|
-----------------------------~-~-~-~-~-~-~-~-~-~-
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Nov 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.