java 如何在 Hybris 灵活搜索查询中使用日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43470287/
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 use Date in Hybris Flexible Search Query?
提问by AppleBud
I am trying to fetch records from hybris using Flexible Search query based on date. I tried to find some resources for the same but none worked out.
我正在尝试使用基于日期的灵活搜索查询从 hybris 中获取记录。我试图找到一些相同的资源,但没有一个成功。
Basically, I am trying to find products where modified date is equals to the current date.
基本上,我试图找到修改日期等于当前日期的产品。
My current query is:
我目前的查询是:
Select * from {product as p} where to_char({p.modifiedDate},'dd/mm/yyyy')==to_char('18/04/2017','dd/mm/yyyy')
This is my current query. However, when I run this using HAC, it give me error:
这是我当前的查询。但是,当我使用 HAC 运行它时,它给了我错误:
xception message: ORA-00936: missing expression
Exception stacktrace:
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017) oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655) oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249) oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566) oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215) oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:58) oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:776) oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:897)
Can anyone help me out on this ?
谁能帮我解决这个问题?
回答by onetuser
As alain.janinm said
正如 alain.janinm 所说
modifiedtime instead of modifiedDate
= instead of ==
I guess you do not need the second to_char because it is already char.
修改时间而不是修改日期
= 而不是 ==
我猜你不需要第二个 to_char 因为它已经是字符了。
Here is official documentation with Oracle and MySQL examples:
以下是 Oracle 和 MySQL 示例的官方文档:
回答by alain.janinm
There are two issues :
有两个问题:
You use ==
to test equality, using one is enough.
你==
用来测试相等性,使用一个就够了。
You use p.modifiedDate
but the field is called modifiedtime
.
您使用p.modifiedDate
但该字段称为modifiedtime
。
The last to_char call is useless.
最后一个 to_char 调用没用。
Unfortunately I can test with an Orale Db but the Flexible search should looks like :
不幸的是,我可以使用 Orale Db 进行测试,但灵活搜索应该如下所示:
SELECT * from {Product as p} where to_char({p.modifiedTime},'dd/mm/yyyy')='18/04/2017'
回答by Claudinei
Please try this solution:
请试试这个解决方案:
{p.modifiedTime} BETWEEN TO_DATE('18/04/2017 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
AND TO_DATE('18/04/2017 23:59:59', 'YYYY-MM-DD HH24:MI:SS')