1

I've tried select REPLACE(' this is a user name', ' ', '') and it gives me 'thisisausername' which is supposed to be.

My problem is, when I try to use REPLACE on selecting a table column, it doesn't work!

My query:

SELECT REPLACE(UserName, ' ', '') as UserName FROM MY_TABLE

it still gives me usernames with spaces! Am I doing something stupid?

22
  • What's the column data-type? Commented Nov 3, 2014 at 17:23
  • 1
    Are you sure it's a space in your username column, and not a tab character? Commented Nov 3, 2014 at 17:24
  • 1
    @eytch that looks like a period not a space :P Commented Nov 3, 2014 at 17:36
  • 1
    @Kritner, it's a leading space Commented Nov 3, 2014 at 17:36
  • 1
    Thats NO-BREAK SPACE (U+00A0) so replace(fld, char(160), '') for that specific case. I would normalize everything to ' ' and check the input sanitization. Commented Nov 3, 2014 at 17:42

1 Answer 1

5

@AlexK. it's 160 for unicode(left(field, 1))

160 is Unicode NO-BREAK SPACE so that's what you need to replace:

replace(UserName, char(160), '')

You could update everything replacing char(160) with a whitespace ' ' and then just use your original query in the future (perhaps also ensuring such values cannot be entered in the future)

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

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.