Milano Milano - 4 months ago 8
SQL Question

How to remove substring from the end of the string

How can I remove a specific substring if this substring is at the end of the string?

In one column, there is

***
at the end - value = 'str***ing***' and I want to strip
***
so the value would be 'str***ing'. I want to delete this substring only from the end of the string.

This is what I have done so far:

I though about
SUBSTR()
but it wants coordinates but the string can be different sizes.

UPDATE final_table SET parametre = ??? WHERE parametre like '%***'

Answer

use substr(your_column , -num)

substr(User.id, -6)

UPDATE final_table SET parametre =  substr(parametre,1, length(parametre)-3) 
WHERE parametre like '%***'
Comments