how to replace multiple strings together in Oracle

前端 未结 5 1547
深忆病人
深忆病人 2020-11-30 13:08

I have a string coming from a table like \"can no pay{1},as your payment{2}due on {3}\". I want to replace {1} with some value , {2} with some value and {3} with some value

5条回答
  •  抹茶落季
    2020-11-30 13:12

    Let's write the same sample as a CTE only:

    with fg_rulez as (
      select 1 id,'<' symbol, 'less than' text from dual
      union all select 2, '>', 'greater than' from dual
       union all select 3, '$', 'dollars' from dual
      union all select 4, '+', 'and' from dual
    ),  fg_Data AS (
       SELECT 'amount $ must be < 1 + > 2' str FROM dual
       union all
       SELECT 'John is > Peter + has many $' str FROM dual
       union all
       SELECT 'Eliana is < mary + do not has many $' str FROM dual
    ), q(str, id) as (
      SELECT str, 0 id 
      FROM fg_Data 
         UNION ALL
      SELECT replace(q.str,symbol,text), fg_rulez.id
      FROM q 
      JOIN fg_rulez 
        ON q.id = fg_rulez.id - 1
    )
    SELECT str from q where id = (select max(id) from fg_rulez);
    

提交回复
热议问题