Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle - Update string to replace only the last character

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), ',', '');
like image 416
PhelpsK Avatar asked Sep 18 '13 17:09

PhelpsK


People also ask

How do I replace a character in a string in Oracle?

Oracle REPLACE() Function This function is used to replace the sequence of character with another character in the given string.


1 Answers

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

like image 178
Vadzim Avatar answered Oct 02 '22 00:10

Vadzim