DBAsupport.com Forums - Powered by vBulletin
Results 1 to 7 of 7

Thread: need something like Replace function

  1. #1
    Join Date
    Dec 2001
    Posts
    19

    need something like Replace function

    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

  2. #2
    Join Date
    May 2002
    Posts
    2,645

  3. #3
    Join Date
    Dec 2001
    Posts
    19
    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.
    Last edited by digiaks; 05-09-2003 at 09:37 PM.

  4. #4
    Join Date
    May 2002
    Posts
    2,645
    Look at decode function. Look at coalesce in 9i.

  5. #5
    Join Date
    Jan 2001
    Posts
    2,828
    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

  6. #6
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    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 . . .)
    "The power of instruction is seldom of much efficacy except in those happy dispositions where it is almost superfluous" - Gibbon, quoted by R.P.Feynman

  7. #7
    Join Date
    Dec 2001
    Posts
    19
    Thanks everyone for the responses. Stecal had what I needed in the decode function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width