you would think this is answered somewhere but I cant find the exact answer. I need to remove the very last character in a string, it can be any character and the string can be any length.
example 992899d needs to be 992899
Any solution using SUBSTRING would only display the field's content by deleting the last character. It would not actually update the content of the column. If that is what you want(i.e. using it with SELECT) then SUBSTRING is enough.
But, if you want to actually update the value of the column, you can try the following:
UPDATE <table_name>
SET <column_name> = CONCAT(LEFT(<column_name>, CHAR_LENGTH(<column_name>) -1), '')
WHERE <condition>;
This would replace the last character with nothing, hence the last character would be deleted.
Refer: http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With