现在有下面2个查询语句
select ltrim('helloworld','hello') from dual
这个函数是截取左边的hello然后剩下world这个没有问题但用rtrim函数截取
select rtrim('helloworld','dlrow') from dual
期望是hello结果只剩下he了
但是如果使用
select rtrim('helloworld','dlro') from dual
这样结果就是
hellow
为什么多了个W结果查这么多

解决方案 »

  1.   

    SYNTAX:     LTRIM(char[,set]) PURPOSE:     Removes characters from the left of char, with initial characters 
        removed up to the first character not in set; set defaults to ' ', a 
        single blank.
      

  2.   

    没错呀,rtrim的作用就是去除指定字符,直到右边不为指定字符位置呀select rtrim('helloworld','dlrow') from dual时,helloworld字符串中向右直到不是'd','l','r','o','w'中的任何一个时就是he了select rtrim('helloworld','dlro') from dual时,helloworld字符串中向右直到不是'd','l','r','o'中任何一个时是'w',所以到'w'就停了
      

  3.   

    如上的ltrim的定义(rtrim类似)。
    ltrim函数的第二个参数是一个字符集合,rtime会去掉集合中的任意字符,直到碰到一个不在集合中的字符;
    所以,如下查询中由于e为从右边开始第一个不在dlrow中的字符,所以剩余结果he正确。
    select rtrim('helloworld','dlrow') from dual 
      

  4.   

    谢谢大家,我明白了,总结一下,ltrim和rtrim函数都是按照第二个参数的字符截取,直到那个字符不是截取的字符为止
    例如select rtrim('helloworld','dlrow') from dual 
    期望是hello结果只剩下he了
    因为前几个字符均在截取的范围之内直到字符e不是为止
    在如
    select rtrim('helloworld','dlro') from dual 
    这样结果就是 
    hellow 
    因为w没有在截取范围之内所以就停止了。