开发者

sql query with space in the value

开发者 https://www.devze.com 2022-12-28 21:47 出处:网络
How do I write where clause 开发者_Python百科where the value has spaces: Actually I am using openJPA and I have to set parameter.

How do I write where clause 开发者_Python百科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.


That should work. The space within the quotes is valid. Perhaps there are spaces after the lastname, or the casing of lastname is incorrect.


That syntax does indeed work; you must be typing in a name that does not exist.

sqlite> CREATE TABLE FOO (name TEXT);
sqlite> INSERT INTO FOO VALUES('joe smith');
sqlite> SELECT * FROM FOO WHERE name = 'joe smith';
joe smith

If this is a one-off search, you might be better off trying the LIKE operator to find the match:

sqlite> SELECT * FROM FOO WHERE name LIKE '%smith%';
joe smith


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消