以下是OCP教材中对该函数的描述
RTRIM(<c1>,<c2> ) takes two arguments, where c1 and c2 are character
strings. This function returns c1 without any trailing characters that appear
in c2. If no c2 characters are trailing characters in c1, then c1 is returned
unchanged. c2 defaults to a single space.
大家对Rtrim舍去字符串右边的空字符串是毫无疑议的
有疑问的应该是右边是字符串如何处理的。
如:
SELECT RTRIM('Mississippi','ip') test1,RTRIM('Rpadded ') test2 ,RTRIM('Mississippi','sip') test3 FROM dual;
结果为:
test1 test3 test3
Mississ Rpadded M
test1的实现
首先从字符串'Mississippi'右边查找'ip'中的任意字符,此例为'i','p',直到'Mississippi'右边不为'i'和'p'字符为止,所以结果应该是Mississ
test2的实现
去掉字符串的空格
test3的实现
实现方法同test1首先从字符串'Mississippi'右边查找'sip'中的任意字符,此例为's','i','p',直到'Mississippi'右边不为's'、'i'和'p'字符为止,所以结果应该是M
可以通过下例进一步了解Rtrim函数
SELECT RTRIM('Mississippi','Misp') test1,RTRIM('Mississippi','i') test2 FROM dual;
test1 test2
Mississipp
再看一个数字的例子
select rtrim('04020000','0')test1,rtrim('04020000','02')test2,rtrim('04020000','04')test3 from dual;
test1 test3 test3
0402 04 0402