Yash_792
Yash_792

Reputation: 45

remove unwanted spaces in string in oracle

I have a query on SQL in Oracle.

I have a text in one of free-text column of an Oracle table.

The value is:

"This is a  test   value"

I want to change this to more appropriate which is

"This is a test value"`

I have used REGEX_REPLACE function however it removed all the spaces. As mentioned I do want the correct space to be displayed in the text but want to remove the unwanted.

Please can anybody help me out in this?

Thanks Yash

Upvotes: 2

Views: 12356

Answers (1)

Hambone
Hambone

Reputation: 16377

This is how I would approach it:

select
  regexp_replace ( 'This is a  test   value', '\s+', ' ')
from dual

Bear in mind this will also replace all multiple whitespaces, such as tabs, as well as spaces. If you really just want spaces:

select
  regexp_replace ( 'This is a  test   value', ' +', ' ')
from dual

Upvotes: 6

Related Questions