MySQL 如何在hibernate和SQL的字符串查询中转义下划线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17102043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to escape underscore in the string query in hibernate and SQL?
提问by user2323036
The _
(underscore) given in the SQL
query is not honored.
不遵守查询中_
给出的(下划线)SQL
。
Example :
例子 :
SELECT * FROM employee WHERE NAME LIKE '%k_p%';
This matches and brings many rows apart from rows which contain k_p
这匹配并带来除了包含的行之外的许多行 k_p
Could someone please assist on how to achieve this in SQL
and also in Hibernate
? Thanks.
可能有人请帮助如何在实现这一目标SQL
以及在Hibernate
?谢谢。
回答by Micha? Powaga
Have you tried escaping it:
你有没有试过逃避它:
SELECT * FROM employee WHERE NAME LIKE '%k\_p%';
\_
instead of just _
.
\_
而不仅仅是_
.
回答by Joginder Malik
I know it is quite late but can be solution for other programmers. You can try
我知道现在已经很晚了,但可以作为其他程序员的解决方案。你可以试试
SELECT * FROM employee WHERE NAME LIKE '%k[_]p%';