DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: SUBSTR vs. RPAD

  1. #1
    Join Date
    Feb 2003
    Location
    Slovakia, Europe
    Posts
    72

    Lightbulb SUBSTR vs. RPAD

    Hello everybody !

    I need to cut the string on specified length. What is better to use ?

    SUBSTR(l_string, 1, 300)
    or
    RPAD(l_string, 300)

    The result is the same, but I would like to know your idea.

    Please comment why substr/rpad.

    Thanks a lot !!

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    But the result is not the same! If your l_string variable contains text with more than 300 characters, then yes, the results will be the same - in both cases you'll get the first 300 characters. But if text in l_string is shorter than 300 characters, then with SUBSTR you'll get the value of the l_string, while with RPAD you'll get the value of l_string, padded with blanks up to the 300 characters. So in this case the results are very different.

    You said you ned "cut the string on specified leng" - the SUBSTR() is the only right thing to use in this case. It's exactly what it does, it cuts the parts of the original string. While on the other hand, RPAD() "adds" something to the original string (with the side effect that sometimes it actually cuts off the original string).
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

Posting Permissions

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


Click Here to Expand Forum to Full Width