Click to See Complete Forum and Search --> : need something like Replace function
digiaks
05-09-2003, 09:19 PM
does a function exist like replace where you can replace multiple values?
Example that shows the idea but does not work is
SELECT REPLACE(field_a,'M','Monday','T','Tuesday')
FROM mytable
TIA
stecal
05-09-2003, 09:25 PM
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#80856
digiaks
05-09-2003, 09:49 PM
I already spent 30 minutes at that site (before coming here) and could not find what I was looking for. the two closest things were replace and translate. neither seem to do what I want. I am sure I am just overlooking something really easy. or it might just exist, but I thought I would try here before I say it can't be done.
stecal
05-09-2003, 11:44 PM
Look at decode function. Look at coalesce in 9i.
hrishy
05-12-2003, 03:48 AM
Hi
"Case" can do this for you as well
select CASE when field_a = 'M' ,'Monday'
when field_a = 'T' ,'TUESDAY'
when ...
else 'Not a Valid Day'
end
from your_table;
regards
Hrishy
If your input string is like: 'MWF' and you want 'MondayWednesdayFriday' as the result, the easiest is
REPLACE(REPLACE(REPLACE(instring,'M','Monday'),'W','Wednesday'),'F','Friday')
(generalise for 7 days . . .)
digiaks
05-15-2003, 05:11 PM
Thanks everyone for the responses. Stecal had what I needed in the decode function.