List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:August 19 1999 7:49pm
Subject:Re: How to query a data with 'backslash' in it?
View as plain text  
On Thu, 1999-08-19 15:05:23 +0800, meng_chiu_lee@stripped wrote:
>  If I insert a data with backslash in it like this:
>  INSERT INTO user1 (userid,name) VALUES ('test1','\\a');
>  
>  select userid,name from user1 where name like '\\a';
>  Empty set (0.00 sec)
>  
>  How can I select exactly the data out from the table not by using any %?

This works:
  SELECT userid, name FROM user1 WHERE name='\\a';

The problem with LIKE and backslashes can be understood, if you read
the paragraph on LIKE in the MySQL manual, chapter "7.3.6 String
comparison functions":

| Note: Because MySQL uses the C escape syntax in strings (e.g.,
| `\n'), you must double any `\' that you use in your LIKE
| strings. For example, to search for `\n', specify it as `\\n'. To
| search for `\', specify it as `\\\\' (the backslashes are stripped
| once by the parser, and another time when the pattern match is done,
| leaving a single backslash to be matched).

So using like, your query shoud look like this:

  SELECT userid, name FROM user1 WHERE name LIKE '\\\\a';
  
Regards,
  Martin
-- 
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
Thread
How to query a data with 'backslash' in it?meng_chiu_lee19 Aug
  • Re: How to query a data with 'backslash' in it?jeremy brand19 Aug
Re: How to query a data with 'backslash' in it?meng_chiu_lee19 Aug
  • Re: How to query a data with 'backslash' in it?Martin Ramsch19 Aug
    • Re: How to query a data with 'backslash' in it?Michael Widenius23 Aug