1

I need to call custom oracle function from spring boot application without using native query.

below is my oracle function which is taking Date as input

create or replace FUNCTION todate(src_dt IN date) 
RETURN date
is
BEGIN 
RETURN(to_date(src_dt)); 
END;

i was searching solution on internet but so far did't find. people are saying some custom dialect need to create but not found any perfect step by step link.

below is my java code :-

 Query query1 = entityManager.createQuery("select todate(ActSubT.createdDt) from ActSubT ActSubT");
  List<Object> result=query1.getResultList();

this code should run , as of now its giving error as todate is oracle function and i haven't configured anything in application.yml file.

Please help

Rajesh Khore
  • 325
  • 1
  • 3
  • 7
  • It's generally helpful to tell us the actual error you get. If you think the error is related to your .yml then maybe include that file? Anyway, your function name is confusing, and it doesn't really make sense - why do you want to call `to_date()` for something that is already a date? At best it's pointless, but it might lose the time portion of the original value (setting it to midnight), or convert incorrectly (possibly losing the century for instance), or error - and behave differently for different users. You should not rely on implicit conversions, or NLS settings... – Alex Poole Aug 09 '19 at 15:44
  • @AlexPoole Don't confuse with given example, my question is how to call database function with createQuery , todate function i just put from example you can consider function name is 'totest()' . below error i am getting org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode \-[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'todate' {originalText=todate} hope it will help . – Rajesh Khore Aug 13 '19 at 06:58
  • Have you read [this](https://thoughts-on-java.org/database-functions/)? It is step by step tutorial. It involves registering custom dialect though. – pavlee Aug 28 '19 at 09:46

0 Answers0