0

I have a comma separated string like

This,is ,a,beautiful ,summer day

Can you please help me remove the WHITESPACE before "comma", without removing the space between two words?

Tried below query:

SELECT regexp_replace('This,is ,a,beautiful  ,summer day'  , '[[:space:]]', null ) regexp
  FROM dual;

but it's removing the space between summer day.

Output:

This,is,a,beautiful,summerday

2 Answers 2

2

You can replace multiple spaces using:

SELECT regexp_replace(
         'This,is ,a,beautiful  ,summer day'  ,
         '[[:space:]]+,',
         ','
       ) regexp
FROM   dual;

Which outputs:

| REGEXP                         |
| :----------------------------- |
| This,is,a,beautiful,summer day |

db<>fiddle here

Sign up to request clarification or add additional context in comments.

Comments

1

As you said - replace it:

SQL> with test (col) as
  2    (select 'This,is ,a,beautiful ,raining day' from dual)
  3           --This,is,a,beautiful,summerday
  4  select replace(col, ' ,', ',') result                 --> this
  5  from test;     

RESULT
-------------------------------
This,is,a,beautiful,raining day

SQL>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.