Oracle - Update string to replace only the last character

PhelpsK picture PhelpsK · Sep 18, 2013 · Viewed 35.1k times · Source

I have the following string in an Oracle 9i database:

A,B,C,

I need to replace all instances of ',' when it is the last item in the string. I have come up with the following statement but it deletes everything in the field not just the comma. Any suggestions?

UPDATE table SET column = REPLACE(SUBSTR(column, -1, 1), ',', '');

Answer

Vadzim picture Vadzim · Jan 14, 2015

rtrim(column, ',') is both efficient and much shorter