473,773 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
+ 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 60276
In article <11************ *********@c13g2 000cwb.googlegr oups.com>,
(ma****@gmail.c om) 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************ **********@z14g 2000cwz.googleg roups.com>,
(ma****@gmail.c om) 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.co m 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************ **********@z14g 2000cwz.googleg roups.com>,
(ma****@gmail.c om) 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**********@f suj29.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(rt rim(NAME)))

HTH
Joachim
<ma****@gmail.c om> schrieb im Newsbeitrag
news:11******** *************@c 13g2000cwb.goog legroups.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.co m 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(LT RIM(' john ')) =>4
Nov 12 '05 #9
ma****@gmail.co m 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.wash ington.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

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

Similar topics

3
3109
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 look like this:
5
5440
by: Daniel | last post by:
c# string size limit? length of string limit?
14
2414
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 }, { "needmailhelo", PRIV_NEEDMAILHELO }, { "needexpnhelo", PRIV_NEEDEXPNHELO }, { "needvrfyhelo", PRIV_NEEDVRFYHELO },
5
1197
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. wchar_t tp = L"Hello"; size_t size = wcsxfrm(NULL, tp, 0); cout<<"Size "<<size<<endl;
4
46138
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 to select max lenth of the String. Any one can help Me?
4
1717
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
5967
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
3750
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 like to remove the weekday information that is "Wed" here, and I also would like to replace the spaces char by "_" and also remove the "\n" char. I didn't know how to truncate the string from beginning or replace some chars in a string with another...
2
2585
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 will be 31/1/2010 then the total length of service will be 29 years, 10 months, 17 days. Kindly help me how to find the length of service in above said format by using VB code in an access project.
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.