Error comparing ORA-00932 dates

Asked

Viewed 7,688 times

3

I’m having a problem comparing two dates in the oracle. I’m using the case method to compare the dates and at the end this should return to my table a number, which in the case represents an age, however, I get p error stating:

PL/SQL: ORA-00932: inconsistent data types: expected DATE got NUMBER.

Below is the code snippet that gives the error.

(case when T1.ANO_MODELO = 0 then 0 else (case when ((W_REG.DAT_ENVIO_CALCULO) - T1.ANO_MODELO) < 0 then 0 else ((W_REG.DAT_ENVIO_CALCULO) - T1.ANO_MODELO) End) End)
  • See the following link in stackoverflow in English. I believe it answers your question. http://stackoverflow.com/questions/11759515/asking-user-to-input-date-in-sql-giving-ora-00932-inconsistent-datatypes-expec

1 answer

2

All the results of your marry must return the same data type. The error occurs because in a situation it returns a number and in another situation returns a date.

The W_REG.DAT_ENVIO_CALCULO is a date? The T1.ANO_MODELO is a number?


[EDIT]

Where do you do:

((W_REG.DAT_ENVIO_CALCULO) - T1.ANO_MODELO)

Replace with:

trunc(
(
W_REG.DAT_ENVIO_CALCULO - to_date(extract(day from W_REG.DAT_ENVIO_CALCULO) || '/' || extract(month from W_REG.DAT_ENVIO_CALCULO) || '/' || T1.ANO_MODELO, 'dd/mm/yyyy')
) / 365 )

This "formula" will return you an integer value that represents the number of years of the vehicle. Do a test and see if you solve.

  • Electus, this is ... The big deal is that in this case, I need to compare the age of a vehicle and do it as follows: W_REG.DAT_ENVIO_CALCULO = normal date format, ex: 21/07/2014 T1.ANO_MODELO = number format, ex: 2011 This way, need to use subtraction to get the age of a vehicle, for example 5 years.

  • I edited my answer.

  • It worked perfectly. Thank you very much.

  • Ok. Since it worked, please mark the answer as correct. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.