1

テーブルにフィールドがあり、日付が格納されています。日付が 5 日であるすべてのレコードを選択したいと思います。

多くの調査の後、以下のコードを取得します。

    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

この選択を行う他の方法はありますか?

ありがとう

4

2 に答える 2

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");
于 2013-01-14T16:38:13.947 に答える
-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;

上記は月曜日に出力されます

それが役立つことを願っています。

于 2013-01-14T16:27:24.850 に答える