1

I need to replace 2 spaces by only 1 space for all entries of 1 column in an Oracle database. I found this and tried it:

SELECT REGEXP_REPLACE('MODEL', '[[:space:]]{2,}', ' ') new_string
FROM ops.TBL_PRODUCT_DEIN_DESIGN;

MODEL is the column name. But it has not replaced the double spaces.

How to use that solution or what could be an alternative?

3
  • well I don't think you need a regular expression here, just try : REPLACE('MODEL',' ', ' ') ;) (note, 2 spaces in quotes, and 1 space, the editor mucks it up a bit)
    – Ditto
    Sep 25, 2015 at 18:01
  • @Ditto: Unless you think there may be more to this problem, I can't see a reason why you shouldn't post your suggestion as an answer.
    – Andriy M
    Sep 26, 2015 at 14:23
  • what is the result of your query?
    – miracle173
    Sep 24, 2018 at 14:35

1 Answer 1

1

You don't need to use a regular expression for that. Instead, you could use the replace function in SQL like this:

replace(MODEL, '  ', ' ')

where MODEL is your column, ' ' is the character(s) that you want to replace and ' ' is the character(s) you want to replace with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.