1

Image Here

I have a column that stores C# codes, how do I remove the last 3 parameters of the "FunctionA"? Note that the column contains multiple functions, but I only need to replace "FunctionA" using PL/SQL, I know REGEXP_REPLACE might do the trick, but I can't seem to find a way to match/replace it.

Before:

Test=FunctionA(varID, 1234,"", A.B,"","","last");

Test=FunctionA(varID, 9876,"", C.D);

Test=FunctionB(varID, 5555,"", E.F,"","","last");

After:

Test=FunctionA(varID, 1234,"", A.B);

Test=FunctionA(varID, 9876,"", C.D);<- should not affect this

Test=FunctionB(varID, 5555,"", E.F,"","","last");<- should not affect this

2
  • I would like to add that the function's parameter values varies for each record, hence I can't use REPLACE function; I need some sort of pattern matching and remove the last 3 parameter for only "FunctionA" Commented May 25, 2018 at 10:15
  • Please edit your original post and include in plain text the "before" data as shown in the image. As a rule, never use images as people trying to help cannot copy/paste to get sample data. Can the string you need to manipulate occur more than once in the chunk of data? Does that data include carriage return/line feeds or is it one long string? Commented May 25, 2018 at 13:33

1 Answer 1

1

Try finding this pattern:

(,[^,]*,[^,]*,[^,]*\);)$

And then replace with just );. Here is a sample query:

SELECT
    REGEXP_REPLACE ('Test=FunctionA(varID, 1234,"", A.B,"","","last");',
        '(,[^,]*,[^,]*,[^,]*\);)$', ');') AS output
FROM dual
WHERE col LIKE 'Test=FunctionA(%'

Test=FunctionA(varID, 1234,"", A.B);

Demo

Edit: I added a WHERE clause which checks the function name.

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

7 Comments

Thanks its very close, but it's affecting all other functions in record example below... SELECT REGEXP_REPLACE ('Test=FunctionA(varID, 1234,"", A.B,"","","last"); Test=FunctionB(varID, 1234,"", A.B,"","","last"); ','(,[^,]*,[^,]*,[^,]*);)$', ');') AS output FROM dual how can you target just "FunctionA"?
@Wakaboom There might be a way to alter the pattern I used in REGEXP_REPLACE but honestly I might just add a WHERE clause which checks the function name to play it safe.
Agree the simple WHERE clause suffice, <hit myself in the head>. So far so good, still playing around with the regex which you have giving, yet to resolve in actual environment. Will post a solution once I found it.
Will post a solution once I found it ... I already found it, at least based on your question. If not, then should edit your question.
SELECT REGEXP_REPLACE ( 'Test=FunctionA(varID, 1234,"", A.B,"","","last"); Test=FunctionB(varID, 1234,"", A.B,"","","last"); Test=FunctionA(varID, 1234,"", A.B,"","","last");', '([FunctionA](varID, 1234,"",[^,]A.B,[^,]*,[^,]*,[^,]*);)', ');') AS output FROM dual I'm getting the below which is wrong... Test=Function); Test=FunctionB(varID, 1234,"", A.B,"","","last"); Test=Function); How can I get the below by modifying the above script?.. Test=FunctionA(varID, 1234,"", A.B); Test=FunctionB(varID, 1234,"", A.B,"","","last"); Test=FunctionA(varID, 1234,"", A.B);
|

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.