Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace specific values in a oracle database column?

I am looking to replace values in a particular column. For example the following column values

column name ---------- Test1 Test2 Test3 Test12 

should be (replacing est1 with rest1)

column name ---------- Trest1 Test2 Test3 Trest12 
like image 542
schar Avatar asked Aug 09 '10 18:08

schar


People also ask

How can I replace one value to another in Oracle?

Oracle provides you with the TRANSLATE() function that has similar functionality as the REPLACE() function. However, the TRANSLATE() function provides single-character, one-to-one substitution, while the REPLACE() function allows you to substitute one string for another.


2 Answers

Use REPLACE:

SELECT REPLACE(t.column, 'est1', 'rest1')   FROM MY_TABLE t 

If you want to update the values in the table, use:

UPDATE MY_TABLE t    SET column = REPLACE(t.column, 'est1', 'rest1') 
like image 61
OMG Ponies Avatar answered Oct 20 '22 00:10

OMG Ponies


If you need to update the value in a particular table:

UPDATE TABLE-NAME SET COLUMN-NAME = REPLACE(TABLE-NAME.COLUMN-NAME, 'STRING-TO-REPLACE', 'REPLACEMENT-STRING'); 

where

  TABLE-NAME         - The name of the table being updated   COLUMN-NAME        - The name of the column being updated   STRING-TO-REPLACE  - The value to replace   REPLACEMENT-STRING - The replacement 
like image 36
Babatunde Adeyemi Avatar answered Oct 20 '22 00:10

Babatunde Adeyemi