Skip to content
Advertisement

ORA-00932: inconsistent datatypes: expected CHAR got NUMBER

Logic

The logic is if an order is cancelled then return 0 otherwise return the owed value – the paid value

Small query

CASE WHEN d.cancelled = 'TRUE' 
     THEN '0' 
     ELSE (to_char(b.owed)) - (to_char(d.paid)) 
     END AS balance,

Getting the error

ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 – “inconsistent datatypes: expected %s got %s” *Cause:
*Action: Error at Line: 25 Column: 58

Advertisement

Answer

Try this, either your case should return number or varchar, right now your case return ‘0’ as varchar and else as number. Either both should return a varchar or both should return a number.

When Both return varchar

CASE WHEN d.cancelled = 'TRUE' 
     THEN '0' 
     ELSE to_char((to_char(b.owed)) - (to_char(d.paid)))
     END AS balance,

OR

When Both return number

CASE WHEN d.cancelled = 'TRUE' 
         THEN 0 
         ELSE (to_char(b.owed)) - (to_char(d.paid))
         END AS balance,

OR

When Both return number

CASE WHEN d.cancelled = 'TRUE' 
         THEN 0 
         ELSE (b.owed - d.paid)
         END AS balance,
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement