0

I have an Oracle DB Table called Details. It has columns end_date and status. Status Could be Active, Expired etc end_date are dates in format YYYY-MM-DD+HH24:MI in varchar datatype.

In a Springboot Java application I need to define a method findAllByFnlColltnDtBeforeNow() in my DetailsRepository Interface which extends CrudRepository

findAllByFnlColltnDtBeforeNow() need to find all records which have

  1. status= ACTIVE,
  2. end_date is not null and
  3. end_date < Sysdate

The query is

@Query(value ="SELECT * FROM DETAILS WHERE UPPER(status)='ACTIVE' AND TRUNC(TO_DATE(end_date, 'YYYY-MM-DD+HH24:MI')) = TRUNC(SYSDATE)-1",nativeQuery = true)
List<Entity> findAllByFnlColltnDtBeforeNow();

The given query works directly in SQLDevloper (OracleDB ), but gives following error when written in Springboot Application

 SQL Error: 1841, SQLState: 22008
 ORA-01841: (full) year must be between -4713 and +9999, and not be 0

This issue occured as soon as i introduced null value in end_date. The query worked directly in SQLDevloper.

I tried using condition "and end_date is not null" but it still shows same issue

Why is the given Query working in SQLDevloper, but throwing error when calling findAllByFnlColltnDtBeforeNow() method? Also How to resolve this?

Vidushi
  • 1
  • 1

0 Answers0