Donovant
Donovant

Reputation: 3161

MySQL: how can I replace only first char if it contains a determinate char?

as title, I would to know how replace only the first char of a record if it contains a determinate char?

For example:

record: " hello" --> record "hello".

Here i remove the space from the string " hello"

Thanks

Upvotes: 1

Views: 5172

Answers (2)

Martin
Martin

Reputation: 1213

If YourField has a space as first character, use this. You can, ofcourse, change the first character to whatever you like.

UPDATE YourTable SET
YourField = RIGHT(YourField,LENGTH(YourField)-1)
WHERE YourField like ' %'

Upvotes: 2

John Bachir
John Bachir

Reputation: 22721

You can't just update "only" the first character, you have to replace the whole column using a regular update.

Upvotes: 0

Related Questions