dbTalk Databases Forums  

How to populate extra bytes when expanding a character column

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss How to populate extra bytes when expanding a character column in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Shishir
 
Posts: n/a

Default How to populate extra bytes when expanding a character column - 09-20-2010 , 04:36 PM






Hi People,


I don't do the DDL's , am just a programmer. But i have following
requirements.
I have to expand a CHAR(9) field to CHAR(12) in a table. Also , i
have to place 3 leading zeros to the
expanded bytes. I mean if i was having '123456789' in the old
field , now i have to have '000123456789' in the
modified field. How can i do that?

Thanks in advance,
Shishir

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: How to populate extra bytes when expanding a character column - 09-20-2010 , 05:24 PM






On 2010-09-20 23:36, Shishir wrote:
Quote:
Hi People,


I don't do the DDL's , am just a programmer. But i have following
requirements.
I have to expand a CHAR(9) field to CHAR(12) in a table. Also , i
have to place 3 leading zeros to the
expanded bytes. I mean if i was having '123456789' in the old
field , now i have to have '000123456789' in the
modified field. How can i do that?

The vanilla way (9.5 LUW):


select * from T2;
X
---------
123456789

alter table T alter column x set data type char(12);
reorg table T;
update T set x = '000' || rtrim(x);

select * from T2;
X
------------
000123456789

/Lennart

Reply With Quote
  #3  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: How to populate extra bytes when expanding a character column - 09-20-2010 , 05:53 PM



On 2010-09-21 00:24, Lennart Jonsson wrote:
[...]

make that:

Quote:
alter table T2 alter column x set data type char(12);
reorg table T2;
update T2 set x = '000' || rtrim(x);
[...]

> /Lennart

Reply With Quote
  #4  
Old   
Shishir
 
Posts: n/a

Default Re: How to populate extra bytes when expanding a character column - 09-20-2010 , 06:23 PM



On Sep 20, 3:53*pm, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com>
wrote:
Quote:
On 2010-09-21 00:24, Lennart Jonsson wrote:
[...]

make that:

alter table T2 alter column x set data type char(12);
reorg table T2;
update T2 set x = '000' || rtrim(x);

[...]



/Lennart- Hide quoted text -

- Show quoted text -
Thanks Lennart
I have another condition added here.
Suppose i don't know how many leading zero's i need to add - it may be
3 , 4 or 5 , how can i go about that.

Reply With Quote
  #5  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: How to populate extra bytes when expanding a character column - 09-20-2010 , 09:26 PM



On 2010-09-21 01:23, Shishir wrote:
[...]
Quote:
Thanks Lennart
I have another condition added here.
Suppose i don't know how many leading zero's i need to add - it may be
3 , 4 or 5 , how can i go about that.


Not tested so there might be an off by one error or such, but the idea
should be ok:

update T2 set x = repeat('0', 12 - length(rtrim(x))) || rtrim(x)


/L

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.