sql查询值中包含空格
如何编写值有空格的 where 子句:
实际上我正在使用 openJPA,我必须设置参数。 我要设置的值有一个空格,例如: String somevalue="名字 姓氏"; 查询.setparameter(somevalue);
我这样做了但不起作用。任何建议将不胜感激。谢谢。
How do I write where clause where the value has spaces:
Actually I am using openJPA and I have to set parameter.
The value i will be setting has a space, eg:
String somevalue="firstname lastname";
query.setparameter(somevalue);
I did this but doesnot work. Any suggestion will be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那应该有效。引号内的空格有效。也许姓氏后面有空格,或者姓氏大小写不正确。
That should work. The space within the quotes is valid. Perhaps there are spaces after the lastname, or the casing of lastname is incorrect.
这种语法确实有效;您输入的名称肯定不存在。
如果这是一次性搜索,您最好尝试
LIKE 运算符
来查找匹配项:
That syntax does indeed work; you must be typing in a name that does not exist.
If this is a one-off search, you might be better off trying the
LIKE
operator to find the match:这个查询没有任何问题。
如果它没有返回结果,那是因为您的数据有问题。您存储为“char”还是“varchar”?如果它是“char”,那么您将有额外的填充字符需要注意。
There's nothing wrong with that query.
If it's not returning results, it's because you've got a problem with your data. Are you storing as 'char' or 'varchar'? If it's 'char', then you'll have extra padding characters in there to watch for.