Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need to remove whitespaces and chr(10) from beginning and end of string

518258Oct 2 2011 — edited Oct 3 2011
Hi All,
I have an requirement where I need to remove all white spaces and carriage return characters from JUST THE beginning and end of the string preserving those from within the string
e.g. string is like 
SELECT '  This is first Line '||chr(10)||' This is second line.  '||chr(10)||'  ' Input_String, 
       REPLACE('  This is first Line '||chr(10)||' This is second line.  '||chr(10)||'  ',' ','#') spaces_replaced,
       REPLACE(REPLACE('  This is first Line '||chr(10)||' This is second line.  '||chr(10)||'  ',' ','#'),chr(10),'@') carriage_returns_replaced,
       'This is first Line '||chr(10)||' This is second line.' Expected_String
FROM DUAL;
The expected output is column expected_string from above query.
If I try with ltrim, rtrim functions I need to write multiple combinations for first trimming chr(10) and then spaces OR first remove spaces and then chr(10) etc.

Is it possible to achieve this using regular expressions? Please help.
Thanks in advance!
This post has been answered by Etbin on Oct 2 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2011
Added on Oct 2 2011
5 comments
5,797 views