SQL 查询查找与 Toplink 中的日期相等的行
我真的很讨厌Oracle中的日期,但我想做的只是一个基本查询来查找一行或多行是否等于日期(Oracle表中日期的格式是17-JAN-11)。我正在使用 Toplink 尝试形成查询。
我的代码是这样的:
ReadAllQuery query = new ReadAllQuery(FooMyTable.class);
ExpressionBuilder builder = query.getExpressionBuilder();
if (dateFoo != null)
query.setSelectionCriteria(builder.getField("REQUEST_CREATED_DATE").equal(dateFoo));
....
它总是带回零行,我猜它是因为我应该使用 truncateDate() 或其他东西,但我无法弄清楚语法。任何人都可以帮忙吗??通过谷歌找不到任何像样的东西,因此这篇文章。
更新:现在我知道这肯定与时间和日期有关 - 对于没有时间的行,它自己只是一个日期,上面的代码可以工作,但是如果日期值也有一个时间,那么它就会失败。
Really hate dates in Oracle but all I want to do is just to a basic query to find whether a row or rows that are equal to a date (the format of the date is 17-JAN-11 in the Oracle table). I am using Toplink to try and form the query.
My code is like this:
ReadAllQuery query = new ReadAllQuery(FooMyTable.class);
ExpressionBuilder builder = query.getExpressionBuilder();
if (dateFoo != null)
query.setSelectionCriteria(builder.getField("REQUEST_CREATED_DATE").equal(dateFoo));
....
It always brings back zero rows and I guess its because I should use truncateDate() or something but I can't figure out the syntax. Can anyone help??, couldn't find anything decent via Google hence this posting.
UPDATE: Now I know it's something definitely to do with time and dates - for rows without time, just a date on it's own, the code above works, but if the date value also has a time with it then it fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所需的实际代码是:
错误消息:
是由于格式掩码不正确 - 因为我需要将日期四舍五入到最近的日期。
Actual code needed is:
The error message:
Was due to the format mask being incorrect - as I required to have the date rounded up to the neareset day.
生成的SQL是什么? truncateDate("DD") 似乎应该有效。
What is the SQL generated? truncateDate("DD") seems like it should work.