Trim Whitespaces (New Line and Tab space) in a String in Oracle

前端 未结 14 901
挽巷
挽巷 2021-01-30 10:29

I need to trim New Line (Chr(13) and Chr(10) and Tab space from the beginning and end of a String) in an Oracle query. I learnt that there is no easy way to trim multiple charac

14条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 11:23

    You could use both LTRIM and RTRIM.

    select rtrim(ltrim('abcdab','ab'),'ab') from dual;
    

    If you want to trim CHR(13) only when it comes with a CHR(10) it gets more complicated. Firstly, translated the combined string to a single character. Then LTRIM/RTRIM that character, then replace the single character back to the combined string.

    select replace(rtrim(ltrim(replace('abccccabcccaab','ab','#'),'#'),'#'),'#','ab') from dual;
    

提交回复
热议问题