Length(Varchar) in db2

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Length(Varchar) in db2

Post by kris007 »

Hi All,
I have a problem with the QA guys.
select min(length(addr1)) from schema.tablename
gives 30. where addr1 is of varchar(30).
I think I have faced this issue even earlier. The length() in db2 gives the size of the datatype rather than actual data value length.But I donot know what other function to suggest. Can any one comment on the observations I made.
Thanks
Kris

Where's the "Any" key?-Homer Simpson
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I'm not at DB/2 right now, but what does "select min(length(TRIM(addr1))) from schema.tablename " return?
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

ArndW wrote:I'm not at DB/2 right now, but what does "select min(length(TRIM(addr1))) from schema.tablename " return?
I tried with min(length(ltrim(rtrim(addr1)))) it is correctly giving as 1.
But when I use min(length(addr1)) I am getting 30. well the problem is QA is complaining about containing spaces well I used trim() in the derivation in transformer stage which should take care of removing spaces in datastage and since datatype is varchar(30) the extra spaces should also not have been added.Not really sure whats happening.
Kris

Where's the "Any" key?-Homer Simpson
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

Does trim() take care of whitespace too? Or should I use stripwhitespace() to remove them explicitly.
Kris

Where's the "Any" key?-Homer Simpson
thumsup9
Charter Member
Charter Member
Posts: 168
Joined: Fri Feb 18, 2005 11:29 am

Post by thumsup9 »

Kris,

What happens when you reload your data using Trim(Convert(Char(000),'',Input)) instead of Trim() in your transformer stage.

Thums!!
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

I ran the same job in a different schema limiting the number of records to only 1000 now I see there are no spaces but when I ran it using LOAD method back in the dev schema I see the spaces in the same records.
Kris

Where's the "Any" key?-Homer Simpson
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

As wierd as it may sound the problem seems to be using LOAD method.
When I use write method I see spaces are being trimmed correctly but when I use LOAD method spaces are not trimmed( or being added back again).Is it because of any environmental variable setting?
Kris

Where's the "Any" key?-Homer Simpson
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is there a CHAR_LENGTH function, or something similar?

Otherwise, use the Len() function within DataStage; the Len() function returns the number of characters in the string.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

No, char_length() function or something similar is not there in db2 udb.
I found the problem is because of the LOAD method that's used when I changed it to write everything is getting trimmed correctly. Not sure if thats stage related (DB2 Enterprise Stage), I should explore other stages available for DB2.
Kris

Where's the "Any" key?-Homer Simpson
Post Reply