Skip to content
Advertisement

Conditional where clause in Oracle SQL query is not working

I am trying to do a select on Oracle DB with this condition but it is not working.

LocalDateTime endDate = null;

Table POST

ID NUMBER
DATE_END TIMESTAMP(6)
select p.id from post p where (:endDate is null or p.date_end < :endDate);

but when endDate is null I got the error

ORA-00932 inconsistent datatypes expected TIMESTAMP got NUMBER.

Please help

Advertisement

Answer

The solution was to transform the Date in String, and in the select do this and (:endDate is null or pl.date_end <= TO_DATE(:endDate , ‘yyyy-MM-dd HH:MI:SS’))

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement