vivek kumar singh
vivek kumar singh

Reputation: 133

How to replace escape character with a string

I am trying to replace escape character with a string but the query is giving me an irrelevant result

eg- char- '\' replace with 'adfc' with below query

SELECT REPLACE("abcdefgh\i","\\", "adfc" );

output - abcdefghi

Desired output - abcdefghadfci

How can i achieve this in mysql?

Upvotes: 5

Views: 6746

Answers (2)

Poonam Tiwari
Poonam Tiwari

Reputation: 101

use this:

SELECT REPLACE("abcdefgh\\i","\\", "adfc" );

single escape character will automatically escape character, so you need to put double escape character for remove escape character.

Upvotes: 0

Gouda Elalfy
Gouda Elalfy

Reputation: 7023

in your my.ini add this line:

sql-mode="NO_BACKSLASH_ESCAPES"

then restart your mysql server, and replace your query with this:

SELECT REPLACE("abcdefgh\i","\", "adfc" );

reference here

Upvotes: 2

Related Questions