Home > Back-end >  Replace 2 characters with same value
Replace 2 characters with same value

Time:05-31

I want to remove ,0 and | at once from the same value which is here A300,0|A232,0

test table

 ---- ------ --------------------- 
| id   | name                  |
 ---- ------ --------------------- 
|  1   | A300,0|A232,0         |
 ---- ------ ---------------------  

select REPLACE(t.name, "|", " ") as a,
replace(t.name, ',0', '') as b
from test as t;
result 
a = A300,0 A232,0 
b= A300|A232

CodePudding user response:

If I understand you correctly, you could achieve what you want by using REPLACE twice:

SELECT REPLACE(REPLACE(t.name, '|', ' '), ',0', '') AS yourResult
FROM test as t;

CodePudding user response:

SELECT REGEXP_REPLACE(name, '(,0)|(\|)', '')
FROM test;

I.e. simply find ,0 or | and replace all found occurences with empty string.

  • Related