If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Varchar & Rtrim

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-04-04, 07:13
Sandeep Potnis Sandeep Potnis is offline
Registered User
 
Join Date: Aug 2004
Posts: 1
Varchar & Rtrim

A basic question for you gurus.

Say I have a column that is varchar(100). It is possible that there are some padded spaces at the end of data in this column.
Can I use RTRIM here?
How does RTRIM work? Does it make a temp copy of the column? Will it take more temp space than retrieving the data as-is?

Thanks
Reply With Quote
  #2 (permalink)  
Old 10-04-04, 13:16
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
A basic answer from a chela(student)
On disk(db), varchar(100) takes as many bytes as required; no trailing spaces; and control bytes denoting its length; as opposed to char(100) which always takes 100 bytes even if all characters are spaces. When you say select vc from tbl , sql uses 100 characters to DISPLAY the field; basically a fixed size DISPLAY; if you use RTRIM(VC) and vc contained 10 chars, you get 10chars.store_name is varchar(35)
db2 "select concat(rtrim(store_name), 'b') from admin.store"
Sunmar b -- store_name taking 35 bytes
db2 "select concat(rtrim(store_name), 'b') from admin.store"
Sunmarb
rtrim useful to concatenate first_name, MI, last_name to get the whole name
__________________
mota
Reply With Quote
  #3 (permalink)  
Old 10-04-04, 13:22
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
sorry; previous post should read
db2 "select concat(store_name, 'b') from admin.store" results in
Sunmar b
db2 "select concat(rtrim(store_name), 'b') from admin.store" results in
Sunmarb
__________________
mota
Reply With Quote
  #4 (permalink)  
Old 10-04-04, 13:45
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Please realize that the html output is different from what is intended. Extra spaces are ignored. There are actually more spaces in the output than what you see.

Code:
Sunmar                             b
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On