skip to Main Content

I’m looking for doing a select to format some values of my table.

I started to do code but still not working:

    SELECT 
    CASE 
        WHEN name ~* '.*\yfede\y.*' THEN REGEXP_REPLACE(name, '\yfede\y', 'fed.') 
        ELSE name 
    END AS nom_modifie 
FROM InitialValues;

What I want is to modify on my select return value all occurrence of the words which contain "fede" with "fed." so "Federation" becomes "fed." but "Federacion" or all words which start with "Fede" should become "fed." too

Example

2

Answers


  1. Chosen as BEST ANSWER
    SELECT 
        (REGEXP_REPLACE(name, 'yFEDEw*', 'FED.') AS nom_modifie
    From InitialVallues;
    

  2. CASE is redundant. Use this regexp m[[:alpha:]]*fede[[:alpha:]]*M with the query:

    select
      regexp_replace(name, 'm[[:alpha:]]*fede[[:alpha:]]*M', 'fed.', 'i') as nom_modifie 
    from InitialValues;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search