1

how to multiple replacement string using regexp_replace in oracle?

formula = 1*3

formula detail (1->value1, 2->value3, 3->value3)

I want the result

formula = value1*value3
3
  • 3
    Please let us know what you've tried so far Commented Apr 24, 2019 at 4:28
  • Look into this and this. Commented Apr 24, 2019 at 7:23
  • I've try using regexp_substr and level. but its not complete, its just get the arithmetic operator Commented Apr 24, 2019 at 9:28

1 Answer 1

1

I don't understand what this:

formula = 1*3

formula detail (1->value1, 2->value3, 3->value3)

actually represents. What is the first row? Is it a string, stored in some table? Is it a string stored in a variable? Is it the complete string, or is the string just 1*3 (without formula =)?

What is the second row? The same doubts as for the first one.


Anyway: if we pretend that the first row represents a string, while the second represents your wish and not some code, then nested REPLACE (i.e. no regular expressions at all) does the job:

SQL> create or replace function f_rep
  2    (par_1 in varchar2, par_2 in varchar2, par_3 in varchar2)
  3  return varchar2
  4  is
  5    l_str varchar2(200) := 'formula = 1*3';
  6  begin
  7    l_str := replace(replace(replace(l_str, '1', par_1),
  8                                            '2', par_2),
  9                                            '3', par_3);
 10    return l_str;
 11  end;
 12  /

Function created.

SQL> select f_rep('value1', null, 'value3') result from dual;

RESULT
--------------------------------------------------------------------------------
formula = value1*value3

SQL>
Sign up to request clarification or add additional context in comments.

3 Comments

formula is name field column and the value is formula for counting something. and the value is dynamic value.
I've try using replace, but its static
I'm sorry, but I still don't understand what you are saying. If possible, edit the initial message you posted, explain the problem in more details, provide CREATE TABLE and INSERT INTO sample data, attach a screenshot ... whatever you think might be useful to help us help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.