2013-01-14 124 views
1

我在表中有一个字段并存储日期。我想选择所有记录中的日期是一天5JPA 2标准日期从日期

我得到下面的代码了大量的研究后:

Predicate dayValue = cb.equal(cb.function("day", Integer.class, test.<Date>get(Test_.dateInit)), now.get(Calendar.DAY_OF_MONTH)); 

但是,我使用的是Oracle数据库和它没有功能的日子:

[EL Warning]: 2013-01-14 11:51:08.001--UnitOfWork(23011228)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException 
Internal Exception: java.sql.SQLException: ORA-00904: "DAY": invalid identifier 

是否有其他方法可以做到这一点?

感谢

回答

-1

在Oracle中,你可以使用

select to_char (date '2013-01-14', 'D') d from dual; 

给你天数,上面会输出1日

,如果你想看到周一刚刚更改为

select to_char (date '2013-01-14', 'Day') d from dual; 

上面会输出星期一

希望有所帮助。

+0

谢谢,但它不是我问。 – javando

+0

我可以看到你对它进行了排序,另一种方法是编写一个小程序来计算一周中的某一天,例如在java中你可以做Calendar c = Calendar.getInstance(); c.setTime(yourDate); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); – justMe

1

我得到了一个方法。

在功能的方法,使用Oracle的功能TO_CHAR:

Predicate dayValue = cb.equal(cb.function("to_char", Integer.class, test.<Date>get(Test_.dateInit),cb.parameter(String.class, "dayFormat")), now.get(Calendar.DAY_OF_MONTH)); 
... 
q.setParameter("dayFormat", "DD");