To remove spaces at the end of each line you could use regexp_replace()
regular expression function:
regexp_replace(col, '\s+('||CHR(10)||'|$)', chr(10))
Here is an example(Note: replace
function is used just to highlight spaces):
with t1(col) as(
select to_clob('begin '||chr(10)||chr(32)||chr(32)||'something is going on here'||chr(32)||chr(32)||chr(10)|| 'end'||chr(32)||chr(32))
from dual
)
select replace(col, ' ', '_') as with_spaces
, replace(
regexp_replace(col, '\s+('||CHR(10)||'|$)', chr(10))
, ' '
, '_'
) as without_spaces
from t1
Result:
WITH_SPACES WITHOUT_SPACES
---------------------------------------------------------------------
begin__ begin
__something_is_going_on_here__ __something_is_going_on_here
end__ end