Reputation: 81
I have one table emp in MySQL database having column as name. In that name column, the value is 'abc\xyz'. I want to search this value. I have tried using following query:
select * from emp where name like 'abc\xyz';
Also i have tried
select * from emp where name like 'abc\xyz' escape '\\';
But i did not found any output. Could you please help me in finding such strings? Such strings can have special character at any location.
Thanks in advance.
Upvotes: 1
Views: 3484
Reputation: 172378
You may try like this:
select * from emp
where empname like '%abc\\\\xyz%'
From the docs:
Because MySQL uses C escape syntax in strings (for example, “\n” to represent a newline character), you must double any “\” that you use in LIKE strings. For example, to search for “\n”, specify it as “\\n”. To search for “\”, specify it as “\\\\”; this is because the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched against.
Upvotes: 3
Reputation: 72
SELECT REPLACE(text,'\\','') FROM tbl
You can use REPLACE to remove some special chars :)
Upvotes: 0