Rajeev
Rajeev

Reputation: 46919

Check spaces in mysql field

 select name from emp_profile;

    Result:
     [email protected]

In the above result how to determine whether there are trailing spaces in it or not

Upvotes: 1

Views: 4397

Answers (2)

Jaydee
Jaydee

Reputation: 4158

If name is a char field it wil not have trailing spaces as far as I can ascertain varchar's do have trailing spaces.

An easy way to check for trailing whitespace to check the length against the trimmed length. rtrim()

Upvotes: 1

Pekka
Pekka

Reputation: 449435

RTRIM() removes trailing spaces.

If RTRIM(name) varies from name, there are trailing spaces in the field.

Related functions are LTRIM() (trims starting spaces) and TRIM() (both sides)

As a side note, I would recommend removing trailing spaces (and other invalid data) during input time on application level, not in the database.

Upvotes: 3

Related Questions