Results 1 to 4 of 4

Thread: Varchar & Rtrim

  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Unanswered: 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

  2. #2
    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

  3. #3
    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

  4. #4
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •