SUBSTR vs. RPAD
Hello everybody !
I need to cut the string on specified length. What is better to use ?
SUBSTR(l_string, 1, 300)
The result is the same, but I would like to know your idea.
Please comment why substr/rpad.
Thanks a lot !!
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).
ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Click Here to Expand Forum to Full Width