Skip to content
Advertisement

How to escape underscore in the string query in hibernate and SQL?

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.

Advertisement

Answer

Have you tried escaping it:

SELECT * FROM employee WHERE NAME LIKE '%k_p%';

_ instead of just _.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement