Reputation: 11
Working in peoplesoft and keep getting the following error related to the expression below:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE expresssion:
CASE WHEN K.DUE_DT - K.PRIOR_DAYS >= TRUNC(SYSDATE) THEN K.DUE_DATE
I did some googling and came up with this but I get the same error
(
CASE
WHEN to_date(K.DUE_DT, 'YYYY-MM-DD') - to_date(K.PRIOR_DAYS, 'YYYY-MM-DD')
>= to_date(TRUNC(SYSDATE), 'YYYY-MM-DD')
THEN to_date(K.DUE_DT,'YYYY-MM-DD')
END
)
Upvotes: 1
Views: 601
Reputation: 3970
Your comparision is wrong difference of dates gives a number of days not date so comparing a number with a date is pointless likewise Oracle gives the error
Upvotes: 0
Reputation: 142705
This is what you have:
WHEN to_date(K.DUE_DT, 'YYYY-MM-DD') - to_date(K.PRIOR_DAYS, 'YYYY-MM-DD') >= to_date(TRUNC(SYSDATE), 'YYYY-MM-DD')
Apart from what you've been told about applying TO_DATE
function to something that already is date (i.e. SYSDATE
in this case, maybe even due_dt
and prior_days
as well, if those are DATE
s), here's how it goes: code you wrote means this:
due_dt - prior_days
)>= sysdate
(i.e. date)
when 4 > 2019-11-22 then ...
expected NUMBER got DATE
Can it be fixed? Sure, only if we knew what you want to do. Hopefully, what I wrote will help you do it.
Upvotes: 1