0

I store numeric variables in a string. Like:165,37,0,0,21

Now i have to change only the last part but keep the rest the same. (in my example i need to change 21 to 0)

Do you have any ideas?

A Redfearn
  • 506
  • 5
  • 15

2 Answers2

0

I sugest using regular expression for this, the below reg ex will find the number at the end of the string, including the last comma, and replace it with ',0'

UPDATE table SET column1 = REGEXP_REPLACE(column1 , ',[0-9]*$', ',0')
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
-1

REPLACE would be most ideal in this case:

UPDATE tbl_name 
SET 
field_name = REPLACE(field_name,
    string_to_find,  -- in your case 21
    string_to_replace  -- in your case 0 ) 
WHERE
<place condition if any e.g. the key to that record>;
Code Chef
  • 82
  • 3