473,472 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to find actual LENGTH of a CHAR string

Hi,
I am using DB2 version 8.2 on Windows XP platform.

I have a table 'EMP' with one field named 'NAME' of type CHAR , size
80.

Also , I have a record with NAME='john'

Now, when I try to find the length of the this name field DB2 returns
80 . Can someone tell me how do I find the actual length of this NAME
field value ('john') without making use of RTRIM.

I say without using RTRIM because, I want to be able to find out the
length of char strings like ' john ' as well .
Thanks in advance
mailar

Nov 12 '05 #1
11 60145
In article <11*********************@c13g2000cwb.googlegroups. com>,
(ma****@gmail.com) says...
Hi,
I am using DB2 version 8.2 on Windows XP platform.

I have a table 'EMP' with one field named 'NAME' of type CHAR , size
80.

Also , I have a record with NAME='john'

Now, when I try to find the length of the this name field DB2 returns
80 . Can someone tell me how do I find the actual length of this NAME
field value ('john') without making use of RTRIM.

I say without using RTRIM because, I want to be able to find out the
length of char strings like ' john ' as well .
Thanks in advance
mailar


You could make it a varchar or fill the remaining part of the column
with a special character.
Nov 12 '05 #2
Hi,
I do not want to make it a VARCHAR field.

Also , my application does not make sense if I fill the remaining part
with some other characters.

Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.

Nov 12 '05 #3
In article <11**********************@z14g2000cwz.googlegroups .com>,
(ma****@gmail.com) says...
Hi,
I do not want to make it a VARCHAR field.

Also , my application does not make sense if I fill the remaining part
with some other characters.
You can't strip them before 'using' the original data?
Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.


Not if you don't want to change it to varchar. Maybe adding a column
containing the original length will help?
Nov 12 '05 #4
ma****@gmail.com wrote:
Hi,
I do not want to make it a VARCHAR field.
Why don't you want to use VARCHAR?

CHAR(X) means that all strings stored in that column will always have a
length of X. If the strings are not long enough when you insert them, DB2
will pad whitespaces to bring them to the required length. That's the
definition of the CHARACTER data type.

VARCHAR(X) tells the database engine that you want to store strings that are
at most X bytes long. Internally, DB2 will store the information about the
actual length of a string, along with the string data itself. So you have
an overhead of at most 2 bytes for each value you insert. On the upside,
you store only "2 + n" bytes for each string, where "n" is the actual
length. That means, if your strings are usually shorter than X, you will
actually save space. And the next plus point is that the strings are
stored right as they are inserted without any padding taking place.
Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.


Decide what you want:

- no padding --> use VARCHAR (or some work-around with special characters)
- CHARACTER --> your strings will be padded to the required length

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #5
Gert van der Kooij wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
(ma****@gmail.com) says...
Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.


Not if you don't want to change it to varchar. Maybe adding a column
containing the original length will help?


Ugh. That's just simulating VARCHAR on a higher level. I would
definitively push such logic to the DBMS and stick to VARCHAR in the first
place.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6
In article <cs**********@fsuj29.rz.uni-jena.de>, Knut Stolze
(st****@de.ibm.com) says...
Not if you don't want to change it to varchar. Maybe adding a column
containing the original length will help?


Ugh. That's just simulating VARCHAR on a higher level. I would
definitively push such logic to the DBMS and stick to VARCHAR in the first
place.


Yep, that's right. I would never do that in my own application,
changing to varchar would be my choice.
Nov 12 '05 #7
Try length(ltrim(rtrim(NAME)))

HTH
Joachim
<ma****@gmail.com> schrieb im Newsbeitrag
news:11*********************@c13g2000cwb.googlegro ups.com...
Hi,
I am using DB2 version 8.2 on Windows XP platform.

I have a table 'EMP' with one field named 'NAME' of type CHAR , size
80.

Also , I have a record with NAME='john'

Now, when I try to find the length of the this name field DB2 returns
80 . Can someone tell me how do I find the actual length of this NAME
field value ('john') without making use of RTRIM.

I say without using RTRIM because, I want to be able to find out the
length of char strings like ' john ' as well .
Thanks in advance
mailar

Nov 12 '05 #8
ma****@gmail.com wrote:
Hi,
I am using DB2 version 8.2 on Windows XP platform.

I have a table 'EMP' with one field named 'NAME' of type CHAR , size
80.

Also , I have a record with NAME='john'

Now, when I try to find the length of the this name field DB2 returns
80 . Can someone tell me how do I find the actual length of this NAME
field value ('john') without making use of RTRIM.

I say without using RTRIM because, I want to be able to find out the
length of char strings like ' john ' as well .
Thanks in advance
mailar

LENGTH(RTRIM(LTRIM(' john ')) =>4
Nov 12 '05 #9
ma****@gmail.com wrote:
Hi,
I do not want to make it a VARCHAR field.

Also , my application does not make sense if I fill the remaining part
with some other characters.

Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.


Are you a student? It makes no sense to use a fixed length data type
and then expect it to be something other than fixed length.

--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Nov 12 '05 #10
Yes, I am a DB2 student.

By the way, can someone tell me that is there a way by which I can
temporarily change this default padding chracter from whitespace to
something else.
Also , is there a way to write a triger on built in functions like
CHAR() ?

Thanks in advance
mailar

DA Morgan wrote:
ma****@gmail.com wrote:
Hi,
I do not want to make it a VARCHAR field.

Also , my application does not make sense if I fill the remaining part with some other characters.

Is there a way by which I can figure out what value the user has
entered in the column and know the length of this value without
including the remaining white spaces padded by DB2.
Are you a student? It makes no sense to use a fixed length data type
and then expect it to be something other than fixed length.

--
Daniel A. Morgan
University of Washington
da******@x.washington.edu
(replace 'x' with 'u' to respond)
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet

News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World!
100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Nov 12 '05 #11
Serge Rielau schrieb:
ma****@gmail.com wrote:
I say without using RTRIM because, I want to be able to find out the
length of char strings like ' john ' as well .
LENGTH(RTRIM(LTRIM(' john ')) =>4


could be:
LENGTH(RTRIM(LTRIM('.' || ' john ' || '.'))) - 2 =>9
Nov 12 '05 #12

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

Similar topics

3
by: Andreas Müller | last post by:
hi @all, I have a char* string array and i want to fill it up in a while loop: while(i<3){ length = read(STDIN_FILENO, inputBuffer, sizeof(inputBuffer); ... } after this the array should...
5
by: Daniel | last post by:
c# string size limit? length of string limit?
14
by: gustavo | last post by:
I was looking at the Sendmail's source code, and i've got confused about this kind of initialization: ------------------------ struct prival PrivacyValues = { { "public", PRIV_PUBLIC }, {...
5
by: Guru | last post by:
Im using VS Studio. Net 2005 to find out the transformed length of wide char string based on specific locale (collation). char* p = setlocale(LC_COLLATE,NULL);//US Locale on my machine. ...
4
by: krndhi1983 | last post by:
Hi to All, I need a query to Find out the max.length of string in a particular Column. For ex. In a table,One of the column name is EmpName, In this column I want...
4
by: sunil | last post by:
How do I find the length of page in target iframe? I am looking for the code or give me idea to find the length
9
by: goelvivek | last post by:
write a program to find the length of the string without using control structures and without using string.h header files???
13
by: Hongyu | last post by:
Hi, I have a datetime char string returned from ctime_r, and it is in the format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars including the last terminate char '\0', and i would...
2
by: karimufeed | last post by:
I am working on an access project for pension calculation. I want to find total length of service between two dates. i.e. if the Date of entry into service is 15/3/1980 and the date of retirement...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.