英文:
How to call Oracle function with date param via EclipseLink with nativeQuery?
问题
我有以下代码,我传递了四个参数,第二个参数是LocalDate。但是它在数据库端抛出无效标识符异常,ORA-00904。
final EntityManager entityManager = factory.createEntityManager();
final LocalDate applicationDate = LocalDate.of(consignmentRequest.getYear(), consignmentRequest.getMonth(), consignmentRequest.getDay());
final String applicationDateParameter = applicationDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
final String businessPartnerId = consignmentRequest.getBusinessPartnerId();
final BigDecimal creditAmount = consignmentRequest.getCreditAmount();
final Integer queryId = consignmentRequest.getEgmQueryId();
final String FUNCTION_CALL_QUERY = "SELECT FN_VEHICLE_CONTROL(?1,?2,?3,?4) FROM DUAL";
final BigDecimal value = (BigDecimal) entityManager
.createNativeQuery(FUNCTION_CALL_QUERY)
.setParameter(1, businessPartnerId)
.setParameter(2, applicationDateParameter)
.setParameter(3, creditAmount)
.setParameter(4, queryId)
.getSingleResult();
entityManager.close();
下面是我的Oracle函数签名:
CREATE OR REPLACE FUNCTION GLOBAL.FN_VEHICLE_CONTROL (
seller VARCHAR2,
myDate DATE,
amount NUMBER,
queryId NUMBER)
RETURN NUMBER
我该如何将LocalDate参数传递给查询?
英文:
I have a below code which I am passing four paremeters and second one is Localdate. But it gives me invalid identifer exception, in DB side ORA-00904
final EntityManager entityManager = factory.createEntityManager();
final LocalDate applicationDate = LocalDate.of(consignmentRequest.getYear(), consignmentRequest.getMonth(), consignmentRequest.getDay());
final String applicationDateParameter = applicationDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
final String businessPartnerId = consignmentRequest.getBusinessPartnerId();
final BigDecimal creditAmount = consignmentRequest.getCreditAmount();
final Integer queryId = consignmentRequest.getEgmQueryId();
final String FUNCTION_CALL_QUERY = "SELECT FN_VEHICLE_CONTROL(?1,?2,?3,?4) FROM DUAL";
final BigDecimal value = (BigDecimal) entityManager
.createNativeQuery(FUNCTION_CALL_QUERY)
.setParameter(1, businessPartnerId)
.setParameter(2, applicationDateParameter)
.setParameter(3, creditAmount)
.setParameter(4, queryId)
.getSingleResult();
entityManager.close();
Below also my Oracle function signature,
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
CREATE OR REPLACE FUNCTION GLOBAL.FN_VEHICLE_CONTROL (
seller VARCHAR2,
myDate DATE,
amount NUMBER,
queryId NUMBER)
RETURN NUMBER
<!-- end snippet -->
How can I pass Localdate parameter to query?
专注分享java语言的经验与见解,让所有开发者获益!
评论