1

I'm a newbie in regular expressions. I want to replace any text string symbols like (,),[,] to hyphens (for example):

SELECT REGEXP_REPLACE ('(<FIO>)', '(', '-') FROM dual;

This gives me ORA-12725 error.

Please, explain me, what's wrong? Thanks.

2
  • I believe you need to escape the parentheses. Commented Apr 17, 2013 at 8:15
  • Do you mean '/' symbol? Could you, please give me an example? Commented Apr 17, 2013 at 8:23

1 Answer 1

3

To replace symbols, use the TRANSLATE function, it is less processor-intensive than regular expression functions:

SQL> SELECT translate ('(<FIO>)', '()[]', '----') replaced FROM dual;

REPLACED
--------
-<FIO>-

Regular expressions are more versatile and can do more complex things but are more expensive. In this case, replacing one character by another is done more efficiently by a specialized function. If you really want to use regular expressions, you could use REGEXP_REPLACE:

SQL> SELECT regexp_replace ('[(<FIO>)]', '[]()[]', '-', 1, 0) reg FROM dual;

REG
---------
--<FIO>--

Update: If you want to replace only the first symbol, translate won't work. Instead, use:

SQL> SELECT regexp_replace ('[(<FIO>)]', '[]()[]', '-', 1, 1) reg FROM dual;

REG
---------
-(<FIO>)]
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks, Vincent! But, if I need replace only first appearance in the string?
This was not obvious from the statements in your question =) See my updated answer
Yeah, I understood it, sorry)
It seems, I asked wrong question ..I'll try to explain in detail.. Vincent, could you write me on my email? [email protected] I write my program code of my function..
@Sergey - Vincent has answered your question, and your amended requirements. If you asked completely the wrong question then please ask another new question, don't try to tack it onto this one or significantly change what this one was asking.
|

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.