How to make a query with like having a backslash

1

I want to filter "Creaci\u00f3n"

SELECT * FROM database.tabla where columna like "%Creaci\u00f3n%";

How could I do it?

    
asked by Alejandro Edward Avendaño 19.09.2018 в 17:29
source

1 answer

1

the symbol \ is the escape character in mysql .

The manual makes this clear in your documentation.

  

Because MySQL uses C escape syntax in strings (for example, "\ n" to   represent 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.

     

How Mysql uses the C syntax to escape characters (for example   "\ n" to represent a new line), you have to double any "\"   which is used in strings within like. For example to search "\ n" there   to specify "\ n" To search for "\", you must specify it as   "\\\"; this is because the inverted bars are uncovered a   once for the parser and then when it comes to matching, leaving as if   There was only one backslash.

So, in this case, as you need two backslashes, you're going to have to write 8 (yes, 8), or clarify that you're going to use another escape character.

Your options are:

SELECT * FROM database.tabla where columna like "%Creaci\\\\u00f3n%";

o (something that looks better):

SELECT * FROM database.tabla where columna like "%Creaci\u00f3n%" ESCAPE '|';

The latter tells you that you are using as escape character.

    
answered by 19.09.2018 / 17:55
source