0

How can I replace a particular special character with another character?

Eg. In the sentence I want to replace à with a and è with e I want to replace à with a and è with e both in same query.

If I use replace simply it doesn't work in SQL Developer 21.2.

Oraccle database: 12 c

I took dump of the problem character:

select dump('é', 1016) from dual

Result:

Typ=96 Len=2 CharacterSet=AL32UTF8: c3,a9

2
  • 1
    Show us your SQL. Commented Oct 11, 2022 at 11:27
  • 1
    "Doesn't work" provides absolutely no information about your real issue. Please clarify what it means and provide error codes/messages or result you want and result you get along with your current code. Commented Oct 11, 2022 at 20:19

3 Answers 3

2

Just try one of these ways:

  1. Solution 1:
SELECT REPLACE( REPLACE('I want to replace à with a and è with e', 'à', 'a'),'è', 'e') FROM DUAL;
  1. Solution 2:
SELECT translate('I want to replace à with a and è with e', 'àè', 'ae') FROM DUAL;

the second looks like better.

I use Oracle 12C release 2.

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

6 Comments

Unfortunately it doesn't work. Sql developer version is 21.2, could this be environment issue?
Well, it might be, I tested this in Oracle 21c as well. What error are you getting @Velocity ?
No error. It just doesn't replace. No change after running the query.
@Velocity: You are saying that both queries return the original string I want to replace à with a and è with e? That is hard to believe. I tried this with Oracle 11.2, and it worked. I tried this with SQL Developer 22.2, and it worked. It is very unlikely that some older Oracle version fails with these simple queries. And it is very unlikely that some older SQL Developer version somehow prevents Oracle from returning the proper result. Have you tried exact the two queries that Reza is showing?
yes, i used exct query.
|
1

You can achieve this using TRANSLATE() function like this : enter image description here

Comments

0

The REPLACE function can do this:

SELECT REPLACE( 'I want to replace à with a', 'à', 'a') FROM DUAL;

sql editor online

Comments

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.