sql update command to update certain digits in a row of a column with VARCHAR2(9) DATATYPE.
Eg: The row in question reads '063150987' and I want to replace the fourth and fifth digits('15') with '08' for all the rows in that column.
Thank you
Looking for relevant Oracle Whitepapers? Visit the SearchOracle.com Research Library.
randym | Oct 6 2006 12:20PM GMT
Oracle has the Replace function but that will replace all occurances of one value to another. So if you can have multiple “15″ in the field, replace can’t be used for your situation. For your example of replacing 15 with 08, try something like this:
update table
set field = substr(field,1,3) || ‘08′ || substr(field,6,4))
where substr(field,4,2)=’15′;
If the rows will only have a 15 in position 4 and 5, you could use:
update table
set field = replace(field,’15′,’08′);
PasztorZ | Oct 7 2006 3:53AM GMT
A variation to the theme:
UPDATE table SET field = substr(FIELD,1,3)|| ‘08′ || substr(FIELD,6)
WHERE substr(FIELD,4,2) = ‘18′;