The _ (underscore) given in the SQL query is not honored.
Example :
SELECT * FROM employee WHERE NAME LIKE '%k_p%'; This matches and brings many rows apart from rows which contain k_p
Could someone please assist on how to achieve this in SQL and also in Hibernate? Thanks.
Use braces to escape a string of characters or symbols. Everything within a set of braces in considered part of the escape sequence. When you use braces to escape a single character, the escaped character becomes a separate token in the query. Use the backslash character to escape a single character or symbol.
The underscore character ( _ ) represents a single character to match a pattern from a word or string. More than one ( _ ) underscore characters can be used to match a pattern of multiple characters.
If you are searching for an underscore then escape it with a '\' so you would search for' \_'. When matching SQL patterns, you can use these symbols as placeholders: % (percent) to substitute for zero or more characters, or _ (underscore) to substitute for one single character.
The underscore allows for the substitution of a single character in an expression.
Have you tried escaping it:
SELECT * FROM employee WHERE NAME LIKE '%k\_p%'; \_ instead of just _.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With