0

I have table having below records

Sno  A
-    --
1   spoo74399p 
2   spoo75399p 

I want to update the above records by replacing oo (alphabet 'o') by zero

Required OUTPUT
----------------
Sno     A

1   sp0074399p 
2   sp0075399p 
GMB
  • 216,147
  • 25
  • 84
  • 135
Ram
  • 727
  • 2
  • 16
  • 33
  • Duplicate of https://stackoverflow.com/questions/5060526/postgresql-replace-all-instances-of-a-string-within-text-field – newBee Feb 11 '20 at 12:44
  • 1
    Does this answer your question? [postgresql - replace all instances of a string within text field](https://stackoverflow.com/questions/5060526/postgresql-replace-all-instances-of-a-string-within-text-field) – newBee Feb 11 '20 at 12:44

2 Answers2

1

I want to update the above records by replacing oo (alphabet 'o') by zero

Is this what you are looking for?

update mytable set a = replace(a, 'oo', '00')
GMB
  • 216,147
  • 25
  • 84
  • 135
1

I might use REGEXP_REPLACE here to be as specific as possible:

UPDATE yourTable
SET A = REGEXP_REPLACE(A, '^spoo', 'sp00');

This would only target the oo occurring near the beginning, after sp.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360