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

前端 未结 14 890
挽巷
挽巷 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:36

    In cases where the Oracle solution seems overly convoluted, I create a java class with static methods and then install it as a package in Oracle. This might not be as performant, but you will eventually find other cases (date conversion to milliseconds for example) where you will find the java fallback helpful.

    0 讨论(0)
  • 2021-01-30 11:36

    Try the code below. It will work if you enter multiple lines in a single column.

    create table  products (prod_id number , prod_desc varchar2(50));
    
    insert into products values(1,'test first
    
    test second
    
    test third');
    
    select replace(replace(prod_desc,chr(10),' '),chr(13),' ') from products  where prod_id=2; 
    

    Output :test first test second test third

    0 讨论(0)
提交回复
热议问题